Skip to content

Commit 73ce123

Browse files
bdracopatchback[bot]
authored andcommitted
Parametrize leak tests (#10577)
Small cleanup to the leak tests #10569 (comment) (cherry picked from commit 3c60cd2)
1 parent 70036a9 commit 73ce123

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

tests/test_leaks.py

+21-26
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,29 @@
99

1010

1111
@pytest.mark.skipif(IS_PYPY, reason="gc.DEBUG_LEAK not available on PyPy")
12-
def test_client_response_does_not_leak_on_server_disconnected_error() -> None:
13-
"""Test that ClientResponse is collected after server disconnects.
14-
15-
https://github.com/aio-libs/aiohttp/issues/10535
16-
"""
17-
leak_test_script = pathlib.Path(__file__).parent.joinpath(
18-
"isolated", "check_for_client_response_leak.py"
19-
)
20-
21-
with subprocess.Popen(
22-
[sys.executable, "-u", str(leak_test_script)],
23-
stdout=subprocess.PIPE,
24-
) as proc:
25-
assert proc.wait() == 0, "ClientResponse leaked"
26-
27-
28-
@pytest.mark.skipif(IS_PYPY, reason="gc.DEBUG_LEAK not available on PyPy")
29-
def test_request_does_not_leak_when_request_handler_raises() -> None:
30-
"""Test that the Request object is collected when the handler raises.
31-
32-
https://github.com/aio-libs/aiohttp/issues/10548
33-
"""
34-
leak_test_script = pathlib.Path(__file__).parent.joinpath(
35-
"isolated", "check_for_request_leak.py"
36-
)
12+
@pytest.mark.parametrize(
13+
("script", "message"),
14+
[
15+
(
16+
# Test that ClientResponse is collected after server disconnects.
17+
# https://github.com/aio-libs/aiohttp/issues/10535
18+
"check_for_client_response_leak.py",
19+
"ClientResponse leaked",
20+
),
21+
(
22+
# Test that Request object is collected when the handler raises.
23+
# https://github.com/aio-libs/aiohttp/issues/10548
24+
"check_for_request_leak.py",
25+
"Request leaked",
26+
),
27+
],
28+
)
29+
def test_leak(script: str, message: str) -> None:
30+
"""Run isolated leak test script and check for leaks."""
31+
leak_test_script = pathlib.Path(__file__).parent.joinpath("isolated", script)
3732

3833
with subprocess.Popen(
3934
[sys.executable, "-u", str(leak_test_script)],
4035
stdout=subprocess.PIPE,
4136
) as proc:
42-
assert proc.wait() == 0, "Request leaked"
37+
assert proc.wait() == 0, message

0 commit comments

Comments
 (0)