From e09950507a90e866ee8dd6716fd45b8a82e17a6a Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 23 Jun 2023 10:32:14 +0200 Subject: [PATCH 1/4] gh-102251: Fix test_import ref leak test_basic_multiple_interpreters_main_no_reset() does not support rerunning --- Lib/test/test_import/__init__.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index e0e2354ae2f19f..938e7e636a87ec 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -107,6 +107,25 @@ def remove_files(name): rmtree('__pycache__') +def no_rerun(reason): + """Skip rerunning for a particular test. + + WARNING: Use this decorator with care; skipping rerunning makes it + impossible to find reference leaks. Provide a clear reason for skipping the + test using the 'reason' parameter. + """ + def deco(func): + _has_run = False + def wrapper(self): + nonlocal _has_run + if _has_run: + self.skipTest(reason) + func(self) + _has_run = True + return wrapper + return deco + + @contextlib.contextmanager def _ready_to_import(name=None, source=""): # sets up a temporary directory and removes it @@ -1989,10 +2008,6 @@ class SinglephaseInitTests(unittest.TestCase): @classmethod def setUpClass(cls): - if '-R' in sys.argv or '--huntrleaks' in sys.argv: - # https://github.com/python/cpython/issues/102251 - raise unittest.SkipTest('unresolved refleaks (see gh-102251)') - spec = importlib.util.find_spec(cls.NAME) from importlib.machinery import ExtensionFileLoader cls.FILE = spec.origin @@ -2434,6 +2449,7 @@ def test_with_reinit_reloaded(self): # Also, we test with a single-phase module that has global state, # which is shared by all interpreters. + #@no_rerun(reason="rerun not possible; module state is never cleared (see gh-102251)") @requires_subinterpreters def test_basic_multiple_interpreters_main_no_reset(self): # without resetting; already loaded in main interpreter From e5baa024265d9489da7e354e25021f82c34ade3b Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 23 Jun 2023 13:04:24 +0200 Subject: [PATCH 2/4] Doh --- Lib/test/test_import/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 938e7e636a87ec..1114ae22180ec7 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -2449,7 +2449,7 @@ def test_with_reinit_reloaded(self): # Also, we test with a single-phase module that has global state, # which is shared by all interpreters. - #@no_rerun(reason="rerun not possible; module state is never cleared (see gh-102251)") + @no_rerun(reason="rerun not possible; module state is never cleared (see gh-102251)") @requires_subinterpreters def test_basic_multiple_interpreters_main_no_reset(self): # without resetting; already loaded in main interpreter From 0784bc19b8ba5b0f07fd6c15f35e77e10fd4d20f Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 23 Jun 2023 14:17:10 +0200 Subject: [PATCH 3/4] Also skip reruns for test_basic_multiple_interpreters_deleted_no_reset() --- Lib/test/test_import/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 1114ae22180ec7..0a53b4b182e4bd 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -2518,6 +2518,7 @@ def test_basic_multiple_interpreters_main_no_reset(self): # * m_copy was copied from interp2 (was from interp1) # * module's global state was updated, not reset + @no_rerun(reason="rerun not possible; module state is never cleared (see gh-102251)") @requires_subinterpreters def test_basic_multiple_interpreters_deleted_no_reset(self): # without resetting; already loaded in a deleted interpreter From 7083645ce9b2243cf2fa18100390208810d2b566 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 23 Jun 2023 19:50:30 +0200 Subject: [PATCH 4/4] Address review: test_basic_multiple_interpreters_main_no_reset() is not affected --- Lib/test/test_import/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 0a53b4b182e4bd..ec8ccf0bd78d37 100644 --- a/Lib/test/test_import/__init__.py +++ b/Lib/test/test_import/__init__.py @@ -2449,7 +2449,6 @@ def test_with_reinit_reloaded(self): # Also, we test with a single-phase module that has global state, # which is shared by all interpreters. - @no_rerun(reason="rerun not possible; module state is never cleared (see gh-102251)") @requires_subinterpreters def test_basic_multiple_interpreters_main_no_reset(self): # without resetting; already loaded in main interpreter