From e631d986a8d539754748943df924eaa332ce4f35 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Wed, 22 Jun 2022 05:32:30 -0700 Subject: [PATCH] gh-93951: In test_bdb.StateTestCase.test_skip, avoid including auxiliary importers. (GH-93962) (GH-94118) Co-authored-by: Brett Cannon (cherry picked from commit c029b552f39200977325d4351803bdd13ddccc4f) Co-authored-by: Jason R. Coombs --- Lib/test/support/__init__.py | 10 ++++++++++ Lib/test/test_bdb.py | 10 ++++++++++ .../2022-06-17-15-20-09.gh-issue-93951.CW1Vv4.rst | 1 + 3 files changed, 21 insertions(+) create mode 100644 Misc/NEWS.d/next/Tests/2022-06-17-15-20-09.gh-issue-93951.CW1Vv4.rst diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 2aec065d4da457..39b3530905b44d 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -1773,6 +1773,16 @@ def cleanup(): 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 diff --git a/Lib/test/test_bdb.py b/Lib/test/test_bdb.py index 6ec59531fa88f0..87a5ac308a12df 100644 --- a/Lib/test/test_bdb.py +++ b/Lib/test/test_bdb.py @@ -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 @@ -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 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 index 00000000000000..b627466b4b221c --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2022-06-17-15-20-09.gh-issue-93951.CW1Vv4.rst @@ -0,0 +1 @@ +In test_bdb.StateTestCase.test_skip, avoid including auxiliary importers.