]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-93951: In test_bdb.StateTestCase.test_skip, avoid including auxiliary importers...
authorJason R. Coombs <jaraco@jaraco.com>
Wed, 22 Jun 2022 12:05:45 +0000 (08:05 -0400)
committerGitHub <noreply@github.com>
Wed, 22 Jun 2022 12:05:45 +0000 (14:05 +0200)
Co-authored-by: Brett Cannon <brett@python.org>
Lib/test/support/__init__.py
Lib/test/test_bdb.py
Misc/NEWS.d/next/Tests/2022-06-17-15-20-09.gh-issue-93951.CW1Vv4.rst [new file with mode: 0644]

index a875548018b99de3411efb2640224b09d0a66768..c51a1f26f29a6b246ba06ba8b4b3126a43b647ac 100644 (file)
@@ -1768,6 +1768,16 @@ def patch(test_instance, object_to_patch, attr_name, new_value):
     setattr(object_to_patch, attr_name, new_value)
 
 
+@contextlib.contextmanager
+def patch_list(orig):
+    """Like unittest.mock.patch.dict, but for lists."""
+    try:
+        saved = orig[:]
+        yield
+    finally:
+        orig[:] = saved
+
+
 def run_in_subinterp(code):
     """
     Run code in a subinterpreter. Raise unittest.SkipTest if the tracemalloc
index 6ec59531fa88f071320d277f529a92e92b471fdf..87a5ac308a12df4373ab908c7c6bd00d8b74e95f 100644 (file)
@@ -59,6 +59,7 @@ from contextlib import contextmanager
 from itertools import islice, repeat
 from test.support import import_helper
 from test.support import os_helper
+from test.support import patch_list
 
 
 class BdbException(Exception): pass
@@ -713,9 +714,18 @@ class StateTestCase(BaseTestCase):
         with TracerRun(self) as tracer:
             tracer.runcall(tfunc_main)
 
+    @patch_list(sys.meta_path)
     def test_skip(self):
         # Check that tracing is skipped over the import statement in
         # 'tfunc_import()'.
+
+        # Remove all but the standard importers.
+        sys.meta_path[:] = (
+            item
+            for item in sys.meta_path
+            if item.__module__.startswith('_frozen_importlib')
+        )
+
         code = """
             def main():
                 lno = 3
diff --git a/Misc/NEWS.d/next/Tests/2022-06-17-15-20-09.gh-issue-93951.CW1Vv4.rst b/Misc/NEWS.d/next/Tests/2022-06-17-15-20-09.gh-issue-93951.CW1Vv4.rst
new file mode 100644 (file)
index 0000000..b627466
--- /dev/null
@@ -0,0 +1 @@
+In test_bdb.StateTestCase.test_skip, avoid including auxiliary importers.