From 4e9e43a22e18a3f4c65d21ba38610ad600009a56 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Wed, 8 Jan 2025 12:44:29 -0500 Subject: [PATCH] tests: explicitly GC for PyPy in test_do_not_leak_response Fixes #351. Signed-off-by: William Woodruff --- tests/test_adapter.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_adapter.py b/tests/test_adapter.py index 7fd0c59..7b299a2 100644 --- a/tests/test_adapter.py +++ b/tests/test_adapter.py @@ -3,6 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 import gc +import platform import weakref from unittest import mock @@ -82,6 +83,12 @@ def test_do_not_leak_response(self, url, sess): # We should not break this. resp = None + if platform.python_implementation() == "PyPy": + # NOTE: Need to explicitly tell PyPy to collect at this point. + # See: https://github.com/psf/cachecontrol/issues/351 + # See: https://doc.pypy.org/en/latest/cpython_differences.html#differences-related-to-garbage-collection-strategies + gc.collect() + # Below this point, it should be closed because there are no more references # to the session response.