gh-108927: Fix removing testing modules from sys.modules (GH-108952)

It breaks import machinery if the test module has submodules used in
other tests.
This commit is contained in:
Serhiy Storchaka 2023-12-04 17:43:27 +02:00 committed by GitHub
parent c718ab92a5
commit e08b70fab1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 9 deletions

View file

@ -122,10 +122,6 @@ def _load_run_test(result: TestResult, runtests: RunTests) -> None:
# Load the test module and run the tests.
test_name = result.test_name
module_name = abs_module_name(test_name, runtests.test_dir)
# 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"):