From 19ccb8b23b6232698f661a023c2fdcfc3a5f2e58 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Wed, 8 Jan 2025 22:04:31 -0500 Subject: [PATCH] tests: explicitly GC for PyPy in test_do_not_leak_response (#352) --- 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.