diff --git a/tests/test_leaks.py b/tests/test_leaks.py index f527ce18cae..07b506bdb99 100644 --- a/tests/test_leaks.py +++ b/tests/test_leaks.py @@ -9,34 +9,29 @@ @pytest.mark.skipif(IS_PYPY, reason="gc.DEBUG_LEAK not available on PyPy") -def test_client_response_does_not_leak_on_server_disconnected_error() -> None: - """Test that ClientResponse is collected after server disconnects. - - https://github.com/aio-libs/aiohttp/issues/10535 - """ - leak_test_script = pathlib.Path(__file__).parent.joinpath( - "isolated", "check_for_client_response_leak.py" - ) - - with subprocess.Popen( - [sys.executable, "-u", str(leak_test_script)], - stdout=subprocess.PIPE, - ) as proc: - assert proc.wait() == 0, "ClientResponse leaked" - - -@pytest.mark.skipif(IS_PYPY, reason="gc.DEBUG_LEAK not available on PyPy") -def test_request_does_not_leak_when_request_handler_raises() -> None: - """Test that the Request object is collected when the handler raises. - - https://github.com/aio-libs/aiohttp/issues/10548 - """ - leak_test_script = pathlib.Path(__file__).parent.joinpath( - "isolated", "check_for_request_leak.py" - ) +@pytest.mark.parametrize( + ("script", "message"), + [ + ( + # Test that ClientResponse is collected after server disconnects. + # https://github.com/aio-libs/aiohttp/issues/10535 + "check_for_client_response_leak.py", + "ClientResponse leaked", + ), + ( + # Test that Request object is collected when the handler raises. + # https://github.com/aio-libs/aiohttp/issues/10548 + "check_for_request_leak.py", + "Request leaked", + ), + ], +) +def test_leak(script: str, message: str) -> None: + """Run isolated leak test script and check for leaks.""" + leak_test_script = pathlib.Path(__file__).parent.joinpath("isolated", script) with subprocess.Popen( [sys.executable, "-u", str(leak_test_script)], stdout=subprocess.PIPE, ) as proc: - assert proc.wait() == 0, "Request leaked" + assert proc.wait() == 0, message