gh-93951: In test_bdb.StateTestCase.test_skip, avoid including auxili… · python/cpython@798ace5

GitHub

GitHub CopilotWrite better code with AI | MCP RegistryIntegrate external tools | ActionsAutomate any workflow | CodespacesInstant dev environments | IssuesPlan and track work | Code ReviewManage code changes | Code QualityEnforce quality at merge | Why GitHub | Marketplace | View all features | Enterprises | Small and medium teams | Startups | View all use cases | View all industries | View all solutions | AI | Software Development | DevOps | Security | View all topics | Customer stories | Events & webinars | Ebooks & reports | Business insights | Trust center | Partners | View all resources

Original file line numberDiff line numberDiff line change@@ -1681,6 +1681,16 @@ def cleanup():

16811681setattr(object_to_patch, attr_name, new_value)

[email protected]

1685+defpatch_list(orig):

1686+"""Like unittest.mock.patch.dict, but for lists."""

1687+try:

1688+saved=orig[:]

1689+yield

1690+finally:

1691+orig[:] =saved

1692+1693+16841694defrun_in_subinterp(code):

16851695"""

16861696 Run code in a subinterpreter. Raise unittest.SkipTest if the tracemalloc

Original file line numberDiff line numberDiff line change@@ -59,6 +59,7 @@

5959fromitertoolsimportislice, repeat

6060fromtest.supportimportimport_helper

6161fromtest.supportimportos_helper

62+fromtest.supportimportpatch_list

626363646465classBdbException(Exception): pass

@@ -713,9 +714,18 @@ def test_until_in_caller_frame(self):

713714withTracerRun(self) astracer:

714715tracer.runcall(tfunc_main)

715716717+@patch_list(sys.meta_path)

716718deftest_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+foriteminsys.meta_path

726+ifitem.__module__.startswith('_frozen_importlib')

727+ )

728+719729code="""

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.