mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
gh-93951: In test_bdb.StateTestCase.test_skip, avoid including auxiliary importers. (GH-93962) (GH-94119)
Co-authored-by: Brett Cannon <brett@python.org>
(cherry picked from commit c029b552f3
)
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
This commit is contained in:
parent
525ab8f310
commit
798ace50f9
3 changed files with 21 additions and 0 deletions
|
@ -1681,6 +1681,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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
In test_bdb.StateTestCase.test_skip, avoid including auxiliary importers.
|
Loading…
Add table
Add a link
Reference in a new issue