Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-93951: In test_bdb.StateTestCase.test_skip, avoid including auxiliary importers. #93962

Merged
merged 2 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,18 @@ def cleanup():
setattr(object_to_patch, attr_name, new_value)


@contextlib.contextmanager
def patch_list(orig):
"""
Like unittest.mock.patch.dict, but for lists.
"""
jaraco marked this conversation as resolved.
Show resolved Hide resolved
try:
saved = orig[:]
yield
finally:
orig[:] = saved


def run_in_subinterp(code):
"""
Run code in a subinterpreter. Raise unittest.SkipTest if the tracemalloc
Expand Down
10 changes: 10 additions & 0 deletions Lib/test/test_bdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
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
Expand Down Expand Up @@ -713,9 +714,18 @@ def test_until_in_caller_frame(self):
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In test_bdb.StateTestCase.test_skip, avoid including auxiliary importers.