From 339f2608671e6b7bd8494e3dcade0b03cb09c9b5 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 5 Sep 2023 20:34:04 +0300 Subject: [PATCH 01/13] gh-108927: Do not remove tested modules from sys.modules It breaks import machinery if the test module has submodules used in other tests. --- Lib/test/libregrtest/runtest.py | 4 ---- .../next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst diff --git a/Lib/test/libregrtest/runtest.py b/Lib/test/libregrtest/runtest.py index 16ae04191da768..795cd7f9bde853 100644 --- a/Lib/test/libregrtest/runtest.py +++ b/Lib/test/libregrtest/runtest.py @@ -434,10 +434,6 @@ def regrtest_runner(result, test_func, ns) -> None: def _load_run_test(result: TestResult, ns: Namespace) -> None: # Load the test function, run the test function. module_name = abs_module_name(result.test_name, ns.testdir) - - # Remove the module from sys.module to reload it if it was already imported - sys.modules.pop(module_name, None) - test_mod = importlib.import_module(module_name) if hasattr(test_mod, "test_main"): diff --git a/Misc/NEWS.d/next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst b/Misc/NEWS.d/next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst new file mode 100644 index 00000000000000..db3d637248ec1d --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst @@ -0,0 +1,2 @@ +Fixed failure for tests running sequentially in the same process when +test_importlib occurs between two other tests that use test_importlib.util. From e52be9bbbbc57a4bc9b2c6079807feab8004bbc7 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 5 Sep 2023 21:27:07 +0300 Subject: [PATCH 02/13] Update NEWS entry. --- .../Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst b/Misc/NEWS.d/next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst index db3d637248ec1d..760dff51cb031d 100644 --- a/Misc/NEWS.d/next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst +++ b/Misc/NEWS.d/next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst @@ -1,2 +1,4 @@ -Fixed failure for tests running sequentially in the same process when -test_importlib occurs between two other tests that use test_importlib.util. +Fixed order dendence in running tests in the same process +when a test that has submodules (e.g. test_importlib) follows a test that +imports its submodule (e.g. test_importlib.util) and precedes a test +(e.g. test_unittest or test_compileall) that uses that submodule. From 68c014e1df5d813580e8040ac11ed3c3442b13ee Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 6 Sep 2023 11:02:02 +0300 Subject: [PATCH 03/13] Fix unloading the newly imported modules after testing. --- Lib/test/libregrtest/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index ab03647ca5802f..1bff1522c9f4a3 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -463,9 +463,9 @@ def run_test(self, test_index, test_name, previous_test, save_modules): self.accumulate_result(result) # Unload the newly imported modules (best effort finalization) - for module in sys.modules.keys(): + for module in list(sys.modules): if module not in save_modules and module.startswith("test."): - support.unload(module) + sys.modules.pop(module, None) return result @@ -480,7 +480,7 @@ def run_tests_sequentially(self, runtests): import trace self.tracer = trace.Trace(trace=False, count=True) - save_modules = sys.modules.keys() + save_modules = set(sys.modules) msg = "Run tests sequentially" if timeout: From 3f25ab447a52d9102c3004666366878adf97cd7f Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 12 Sep 2023 11:51:48 +0300 Subject: [PATCH 04/13] Add tests. --- .../regrtestdata/import_from_tests/test_regrtest_a.py | 6 ++++++ .../import_from_tests/test_regrtest_b/__init__.py | 5 +++++ .../import_from_tests/test_regrtest_b/util.py | 0 .../regrtestdata/import_from_tests/test_regrtest_c.py | 6 ++++++ Lib/test/test_regrtest.py | 8 ++++++++ 5 files changed, 25 insertions(+) create mode 100644 Lib/test/regrtestdata/import_from_tests/test_regrtest_a.py create mode 100644 Lib/test/regrtestdata/import_from_tests/test_regrtest_b/__init__.py create mode 100644 Lib/test/regrtestdata/import_from_tests/test_regrtest_b/util.py create mode 100644 Lib/test/regrtestdata/import_from_tests/test_regrtest_c.py diff --git a/Lib/test/regrtestdata/import_from_tests/test_regrtest_a.py b/Lib/test/regrtestdata/import_from_tests/test_regrtest_a.py new file mode 100644 index 00000000000000..f225e21bad2e76 --- /dev/null +++ b/Lib/test/regrtestdata/import_from_tests/test_regrtest_a.py @@ -0,0 +1,6 @@ +import unittest +import test_regrtest_b.util + +class Test(unittest.TestCase): + def test(self): + test_regrtest_b.util diff --git a/Lib/test/regrtestdata/import_from_tests/test_regrtest_b/__init__.py b/Lib/test/regrtestdata/import_from_tests/test_regrtest_b/__init__.py new file mode 100644 index 00000000000000..feb9d9781a8225 --- /dev/null +++ b/Lib/test/regrtestdata/import_from_tests/test_regrtest_b/__init__.py @@ -0,0 +1,5 @@ +import unittest + +class Test(unittest.TestCase): + def test(self): + pass diff --git a/Lib/test/regrtestdata/import_from_tests/test_regrtest_b/util.py b/Lib/test/regrtestdata/import_from_tests/test_regrtest_b/util.py new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/Lib/test/regrtestdata/import_from_tests/test_regrtest_c.py b/Lib/test/regrtestdata/import_from_tests/test_regrtest_c.py new file mode 100644 index 00000000000000..f225e21bad2e76 --- /dev/null +++ b/Lib/test/regrtestdata/import_from_tests/test_regrtest_c.py @@ -0,0 +1,6 @@ +import unittest +import test_regrtest_b.util + +class Test(unittest.TestCase): + def test(self): + test_regrtest_b.util diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py index 7cf3d05a6e6d70..c76e17a7cfd6e9 100644 --- a/Lib/test/test_regrtest.py +++ b/Lib/test/test_regrtest.py @@ -1866,6 +1866,14 @@ def test_random_seed(self): def test_random_seed_workers(self): self._check_random_seed(run_workers=True) + def test_import_from_tests(self): + testdir = os.path.join(os.path.dirname(__file__), + 'regrtestdata', 'import_from_tests') + tests = [f'test_regrtest_{name}' for name in ('a', 'b', 'c')] + args = ['-Wd', '-E', '-bb', '-m', 'test', '--testdir=%s' % testdir, *tests] + output = self.run_python(args) + self.check_executed_tests(output, tests, stats=3) + class TestUtils(unittest.TestCase): def test_format_duration(self): From 76732484f08d0a44592f8c7e34a2dea65083f774 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 12 Sep 2023 23:32:03 +0300 Subject: [PATCH 05/13] Update Misc/NEWS.d/next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst Co-authored-by: Brett Cannon --- .../next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst b/Misc/NEWS.d/next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst index 760dff51cb031d..b1a78370afedb2 100644 --- a/Misc/NEWS.d/next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst +++ b/Misc/NEWS.d/next/Tests/2023-09-05-20-46-35.gh-issue-108927.TpwWav.rst @@ -1,4 +1,4 @@ -Fixed order dendence in running tests in the same process +Fixed order dependence in running tests in the same process when a test that has submodules (e.g. test_importlib) follows a test that imports its submodule (e.g. test_importlib.util) and precedes a test (e.g. test_unittest or test_compileall) that uses that submodule. From 5df4c8b0b7b3d502cf244a52ab97e1966f38d6c4 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 13 Sep 2023 10:55:46 +0300 Subject: [PATCH 06/13] Move save/unload modules down in single.py. --- Lib/test/libregrtest/main.py | 7 ------- Lib/test/libregrtest/save_env.py | 12 ++++++++++++ Lib/test/libregrtest/single.py | 7 ++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index 5e4f5739d3a4f1..5cb43b963dadfa 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -293,8 +293,6 @@ def run_tests_sequentially(self, runtests): else: tracer = None - save_modules = set(sys.modules) - jobs = runtests.get_jobs() if jobs is not None: tests = f'{jobs} tests' @@ -317,11 +315,6 @@ def run_tests_sequentially(self, runtests): result = self.run_test(test_name, runtests, tracer) - # Unload the newly imported modules (best effort finalization) - for module in list(sys.modules): - if module not in save_modules and module.startswith("test."): - sys.modules.pop(module, None) - if result.must_stop(self.fail_fast, self.fail_env_changed): break diff --git a/Lib/test/libregrtest/save_env.py b/Lib/test/libregrtest/save_env.py index b2cc381344b2ef..8b2d149d29f963 100644 --- a/Lib/test/libregrtest/save_env.py +++ b/Lib/test/libregrtest/save_env.py @@ -329,3 +329,15 @@ def __exit__(self, exc_type, exc_val, exc_tb): f" Before: {original}\n" f" After: {current} ") return False + + +class saved_sys_modules: + + def __enter__(self): + self.save_modules = set(sys.modules) + + def __exit__(self, exc_type, exc_val, exc_tb): + # Unload the newly imported modules (best effort finalization) + for module in list(sys.modules): + if module not in self.save_modules and module.startswith("test."): + sys.modules.pop(module, None) diff --git a/Lib/test/libregrtest/single.py b/Lib/test/libregrtest/single.py index d491ffb9cd9aa2..b3a504aeee379f 100644 --- a/Lib/test/libregrtest/single.py +++ b/Lib/test/libregrtest/single.py @@ -14,7 +14,7 @@ from .result import State, TestResult from .runtests import RunTests -from .save_env import saved_test_environment +from .save_env import saved_test_environment, saved_sys_modules from .setup import setup_tests from .utils import ( TestName, @@ -127,8 +127,9 @@ def _runtest_env_changed_exc(result: TestResult, runtests: RunTests, clear_caches() support.gc_collect() - with saved_test_environment(test_name, - runtests.verbose, quiet, pgo=pgo): + with (saved_sys_modules(), + saved_test_environment(test_name, + runtests.verbose, quiet, pgo=pgo)): _load_run_test(result, runtests) except support.ResourceDenied as msg: if not quiet and not pgo: From 0eae53539c49a75cb00696b28c541b022ca1d599 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 13 Sep 2023 13:26:34 +0300 Subject: [PATCH 07/13] Refactoring. --- Lib/test/libregrtest/save_env.py | 9 +++++---- Lib/test/libregrtest/single.py | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Lib/test/libregrtest/save_env.py b/Lib/test/libregrtest/save_env.py index 8b2d149d29f963..25d16633e00881 100644 --- a/Lib/test/libregrtest/save_env.py +++ b/Lib/test/libregrtest/save_env.py @@ -331,13 +331,14 @@ def __exit__(self, exc_type, exc_val, exc_tb): return False -class saved_sys_modules: +class saved_test_modules: def __enter__(self): self.save_modules = set(sys.modules) def __exit__(self, exc_type, exc_val, exc_tb): # Unload the newly imported modules (best effort finalization) - for module in list(sys.modules): - if module not in self.save_modules and module.startswith("test."): - sys.modules.pop(module, None) + new_modules = [module for module in sys.modules + if module not in self.save_modules and module.startswith("test.")] + for module in new_modules: + sys.modules.pop(module, None) diff --git a/Lib/test/libregrtest/single.py b/Lib/test/libregrtest/single.py index b3a504aeee379f..5c54419cfa6626 100644 --- a/Lib/test/libregrtest/single.py +++ b/Lib/test/libregrtest/single.py @@ -14,7 +14,7 @@ from .result import State, TestResult from .runtests import RunTests -from .save_env import saved_test_environment, saved_sys_modules +from .save_env import saved_test_environment, saved_test_modules from .setup import setup_tests from .utils import ( TestName, @@ -127,7 +127,7 @@ def _runtest_env_changed_exc(result: TestResult, runtests: RunTests, clear_caches() support.gc_collect() - with (saved_sys_modules(), + with (saved_test_modules(), saved_test_environment(test_name, runtests.verbose, quiet, pgo=pgo)): _load_run_test(result, runtests) From 66437b50b93bfd2fd60e96e7011a44131772ea0a Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 13 Sep 2023 15:29:13 +0300 Subject: [PATCH 08/13] Remove also attributes from parent modules. --- Lib/test/libregrtest/save_env.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/test/libregrtest/save_env.py b/Lib/test/libregrtest/save_env.py index 25d16633e00881..9a5db51d6624a2 100644 --- a/Lib/test/libregrtest/save_env.py +++ b/Lib/test/libregrtest/save_env.py @@ -339,6 +339,13 @@ def __enter__(self): def __exit__(self, exc_type, exc_val, exc_tb): # Unload the newly imported modules (best effort finalization) new_modules = [module for module in sys.modules - if module not in self.save_modules and module.startswith("test.")] + if module not in self.save_modules and + module.startswith("test.")] for module in new_modules: sys.modules.pop(module, None) + # Remove the attribute of the parent module. + parent, _, name = module.rpartition('.') + try: + delattr(sys.modules[parent], name) + except (KeyError, AttributeError): + pass From 56621abe6c06ea57bc2bdca360eea2d6fb4f70b1 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 28 Nov 2023 16:01:33 +0200 Subject: [PATCH 09/13] Only unload modules if run tests sequentially. --- Lib/test/libregrtest/main.py | 15 +++++++++++++++ Lib/test/libregrtest/save_env.py | 20 -------------------- Lib/test/libregrtest/single.py | 7 +++---- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index 5420247f9ad0e0..69ab66272a9609 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -309,6 +309,8 @@ def run_tests_sequentially(self, runtests) -> None: else: tracer = None + save_modules = set(sys.modules) + jobs = runtests.get_jobs() if jobs is not None: tests = count(jobs, 'test') @@ -331,6 +333,19 @@ def run_tests_sequentially(self, runtests) -> None: result = self.run_test(test_name, runtests, tracer) + # Unload the newly imported modules (best effort finalization) + new_modules = [module for module in sys.modules + if module not in save_modules and + module.startswith("test.")] + for module in new_modules: + sys.modules.pop(module, None) + # Remove the attribute of the parent module. + parent, _, name = module.rpartition('.') + try: + delattr(sys.modules[parent], name) + except (KeyError, AttributeError): + pass + if result.must_stop(self.fail_fast, self.fail_env_changed): break diff --git a/Lib/test/libregrtest/save_env.py b/Lib/test/libregrtest/save_env.py index 9a5db51d6624a2..b2cc381344b2ef 100644 --- a/Lib/test/libregrtest/save_env.py +++ b/Lib/test/libregrtest/save_env.py @@ -329,23 +329,3 @@ def __exit__(self, exc_type, exc_val, exc_tb): f" Before: {original}\n" f" After: {current} ") return False - - -class saved_test_modules: - - def __enter__(self): - self.save_modules = set(sys.modules) - - def __exit__(self, exc_type, exc_val, exc_tb): - # Unload the newly imported modules (best effort finalization) - new_modules = [module for module in sys.modules - if module not in self.save_modules and - module.startswith("test.")] - for module in new_modules: - sys.modules.pop(module, None) - # Remove the attribute of the parent module. - parent, _, name = module.rpartition('.') - try: - delattr(sys.modules[parent], name) - except (KeyError, AttributeError): - pass diff --git a/Lib/test/libregrtest/single.py b/Lib/test/libregrtest/single.py index 0851f30feef253..47368eb6ac7a06 100644 --- a/Lib/test/libregrtest/single.py +++ b/Lib/test/libregrtest/single.py @@ -13,7 +13,7 @@ from .filter import match_test from .result import State, TestResult, TestStats from .runtests import RunTests -from .save_env import saved_test_environment, saved_test_modules +from .save_env import saved_test_environment from .setup import setup_tests from .testresult import get_test_runner from .utils import ( @@ -173,9 +173,8 @@ def _runtest_env_changed_exc(result: TestResult, runtests: RunTests, clear_caches() support.gc_collect() - with (saved_test_modules(), - saved_test_environment(test_name, - runtests.verbose, quiet, pgo=pgo)): + with saved_test_environment(test_name, + runtests.verbose, quiet, pgo=pgo): _load_run_test(result, runtests) except support.ResourceDenied as exc: if not quiet and not pgo: From ba5597afa6935cece477d54553c7e859ec61fec3 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 1 Dec 2023 11:15:11 +0200 Subject: [PATCH 10/13] Apply suggestions from code review Co-authored-by: Victor Stinner --- Lib/test/libregrtest/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index 69ab66272a9609..68f1882b316f9f 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -333,7 +333,7 @@ def run_tests_sequentially(self, runtests) -> None: result = self.run_test(test_name, runtests, tracer) - # Unload the newly imported modules (best effort finalization) + # Unload the newly imported test modules (best effort finalization) new_modules = [module for module in sys.modules if module not in save_modules and module.startswith("test.")] From 1aae3412f7fd102525c2ae7ca88b7b196316220a Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 4 Dec 2023 12:57:15 +0200 Subject: [PATCH 11/13] Add a comment. --- Lib/test/test_regrtest.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py index c2a97ec6341027..982f8393cba415 100644 --- a/Lib/test/test_regrtest.py +++ b/Lib/test/test_regrtest.py @@ -2032,6 +2032,17 @@ def test_dev_mode(self): stats=len(tests), parallel=True) def test_import_from_tests(self): + # Test that unloading test modules does not break tests + # that import from other tests. + # The test execution order matters for this test. + # Both test_regrtest_a and test_regrtest_c which are executed before + # and after test_regrtest_b import a submodule from the test_regrtest_b + # package and use it in testing. test_regrtest_b itself does not import + # that submodule. + # Previously test_regrtest_c failed because test_regrtest_b.util in + # sys.modules was left after test_regrtest_a (making the import + # statement no-op), but new test_regrtest_b without the util attribute + # was imported for test_regrtest_b. testdir = os.path.join(os.path.dirname(__file__), 'regrtestdata', 'import_from_tests') tests = [f'test_regrtest_{name}' for name in ('a', 'b', 'c')] From 017f01de9deadc34fd05f1c818e127da3b1a2f86 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 4 Dec 2023 12:57:43 +0200 Subject: [PATCH 12/13] Test that test modules are really unloaded. --- Lib/test/libregrtest/main.py | 2 +- Lib/test/regrtestdata/import_from_tests/test_regrtest_a.py | 7 ++++++- .../import_from_tests/test_regrtest_b/__init__.py | 6 +++++- Lib/test/regrtestdata/import_from_tests/test_regrtest_c.py | 7 ++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index c6cc70618193e1..8bb66f662477b0 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -338,7 +338,7 @@ def run_tests_sequentially(self, runtests) -> None: # Unload the newly imported modules (best effort finalization) new_modules = [module for module in sys.modules if module not in save_modules and - module.startswith("test.")] + module.startswith(("test.", "test_"))] for module in new_modules: sys.modules.pop(module, None) # Remove the attribute of the parent module. diff --git a/Lib/test/regrtestdata/import_from_tests/test_regrtest_a.py b/Lib/test/regrtestdata/import_from_tests/test_regrtest_a.py index f225e21bad2e76..9c3d0c7cf4bfaa 100644 --- a/Lib/test/regrtestdata/import_from_tests/test_regrtest_a.py +++ b/Lib/test/regrtestdata/import_from_tests/test_regrtest_a.py @@ -1,6 +1,11 @@ +import sys import unittest import test_regrtest_b.util class Test(unittest.TestCase): def test(self): - test_regrtest_b.util + test_regrtest_b.util # does not fail + self.assertIn('test_regrtest_a', sys.modules) + self.assertIs(sys.modules['test_regrtest_b'], test_regrtest_b) + self.assertIs(sys.modules['test_regrtest_b.util'], test_regrtest_b.util) + self.assertNotIn('test_regrtest_c', sys.modules) diff --git a/Lib/test/regrtestdata/import_from_tests/test_regrtest_b/__init__.py b/Lib/test/regrtestdata/import_from_tests/test_regrtest_b/__init__.py index feb9d9781a8225..3dfba253455ad2 100644 --- a/Lib/test/regrtestdata/import_from_tests/test_regrtest_b/__init__.py +++ b/Lib/test/regrtestdata/import_from_tests/test_regrtest_b/__init__.py @@ -1,5 +1,9 @@ +import sys import unittest class Test(unittest.TestCase): def test(self): - pass + self.assertNotIn('test_regrtest_a', sys.modules) + self.assertIn('test_regrtest_b', sys.modules) + self.assertNotIn('test_regrtest_b.util', sys.modules) + self.assertNotIn('test_regrtest_c', sys.modules) diff --git a/Lib/test/regrtestdata/import_from_tests/test_regrtest_c.py b/Lib/test/regrtestdata/import_from_tests/test_regrtest_c.py index f225e21bad2e76..de80769118d709 100644 --- a/Lib/test/regrtestdata/import_from_tests/test_regrtest_c.py +++ b/Lib/test/regrtestdata/import_from_tests/test_regrtest_c.py @@ -1,6 +1,11 @@ +import sys import unittest import test_regrtest_b.util class Test(unittest.TestCase): def test(self): - test_regrtest_b.util + test_regrtest_b.util # does not fail + self.assertNotIn('test_regrtest_a', sys.modules) + self.assertIs(sys.modules['test_regrtest_b'], test_regrtest_b) + self.assertIs(sys.modules['test_regrtest_b.util'], test_regrtest_b.util) + self.assertIn('test_regrtest_c', sys.modules) From b3ea8faa682450998b5a912ad44d7a6f4b998027 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 4 Dec 2023 17:08:07 +0200 Subject: [PATCH 13/13] Update Lib/test/test_regrtest.py Co-authored-by: Victor Stinner --- Lib/test/test_regrtest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py index 982f8393cba415..e828941f6c779d 100644 --- a/Lib/test/test_regrtest.py +++ b/Lib/test/test_regrtest.py @@ -2031,7 +2031,7 @@ def test_dev_mode(self): self.check_executed_tests(output, tests, stats=len(tests), parallel=True) - def test_import_from_tests(self): + def test_unload_tests(self): # Test that unloading test modules does not break tests # that import from other tests. # The test execution order matters for this test.