Skip to content

Commit fd71a10

Browse files
committed
Filter known anyio stream teardown warnings in streamable HTTP security tests
The three tests that complete the initialize handshake leak anyio memory streams at transport teardown when run in process. The scoped filters in tests/interaction/conftest.py cover full-suite runs, but they only load when that package is collected, so a targeted run of this file alone turns the ResourceWarning into a failure under filterwarnings=error. Mirror the module-level filterwarnings marks already used in tests/shared/test_sse.py.
1 parent 6a6e7b7 commit fd71a10

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tests/server/test_streamable_http_security.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@
1919
# Host header is a localhost form; nothing listens here.
2020
BASE_URL = "http://127.0.0.1:8000"
2121

22+
# v1's streamable-HTTP server transport leaks a handful of anyio memory streams on teardown when
23+
# run in process; the old subprocess harness never observed them. The interaction suite registers
24+
# the same two scoped filters globally from tests/interaction/conftest.py (see the comment there),
25+
# but they only take effect when that package's conftest is loaded; these markers keep the tests
26+
# that complete the initialize handshake passing in isolated runs. Markers are item-scoped, so
27+
# they cannot cover the GC flush at session cleanup: an isolated run without xdist (`-n 0`) still
28+
# exits nonzero after all tests pass. The default xdist runs (addopts has `-n auto`) are
29+
# unaffected, as are full-suite runs, where the interaction conftest's ini-level filters apply.
30+
# The filters are scoped to anyio's MemoryObject*Stream leak signature so an unrelated leak
31+
# still fails the suite.
32+
pytestmark = [
33+
pytest.mark.filterwarnings("ignore:.*MemoryObject(Send|Receive)Stream:pytest.PytestUnraisableExceptionWarning"),
34+
pytest.mark.filterwarnings("ignore:.*MemoryObject(Send|Receive)Stream:ResourceWarning"),
35+
]
36+
2237

2338
@asynccontextmanager
2439
async def streamable_http_security_client(

0 commit comments

Comments
 (0)