Skip to content

Commit e631d98

Browse files
pythongh-93951: In test_bdb.StateTestCase.test_skip, avoid including auxiliary importers. (pythonGH-93962) (pythonGH-94118)
Co-authored-by: Brett Cannon <[email protected]> (cherry picked from commit c029b55) Co-authored-by: Jason R. Coombs <[email protected]>
1 parent 6c18bd5 commit e631d98

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

Lib/test/support/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,16 @@ def cleanup():
17731773
setattr(object_to_patch, attr_name, new_value)
17741774

17751775

1776+
@contextlib.contextmanager
1777+
def patch_list(orig):
1778+
"""Like unittest.mock.patch.dict, but for lists."""
1779+
try:
1780+
saved = orig[:]
1781+
yield
1782+
finally:
1783+
orig[:] = saved
1784+
1785+
17761786
def run_in_subinterp(code):
17771787
"""
17781788
Run code in a subinterpreter. Raise unittest.SkipTest if the tracemalloc

Lib/test/test_bdb.py

+10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
from itertools import islice, repeat
6060
from test.support import import_helper
6161
from test.support import os_helper
62+
from test.support import patch_list
6263

6364

6465
class BdbException(Exception): pass
@@ -713,9 +714,18 @@ def test_until_in_caller_frame(self):
713714
with TracerRun(self) as tracer:
714715
tracer.runcall(tfunc_main)
715716

717+
@patch_list(sys.meta_path)
716718
def test_skip(self):
717719
# Check that tracing is skipped over the import statement in
718720
# 'tfunc_import()'.
721+
722+
# Remove all but the standard importers.
723+
sys.meta_path[:] = (
724+
item
725+
for item in sys.meta_path
726+
if item.__module__.startswith('_frozen_importlib')
727+
)
728+
719729
code = """
720730
def main():
721731
lno = 3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In test_bdb.StateTestCase.test_skip, avoid including auxiliary importers.

0 commit comments

Comments
 (0)