Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-102251: Fix test_import ref leak
test_basic_multiple_interpreters_main_no_reset() does not support rerunning
  • Loading branch information
erlend-aasland committed Jun 23, 2023
commit e09950507a90e866ee8dd6716fd45b8a82e17a6a
24 changes: 20 additions & 4 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down