result.stats = stats
-def save_env(test_name: TestName, runtests: RunTests):
- return saved_test_environment(test_name, runtests.verbose, runtests.quiet,
- pgo=runtests.pgo)
-
-
# Storage of uncollectable GC objects (gc.garbage)
GC_GARBAGE = []
def _load_run_test(result: TestResult, runtests: RunTests) -> None:
- # Load the test function, run the test function.
- module_name = abs_module_name(result.test_name, runtests.test_dir)
+ # 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)
if hasattr(test_mod, "test_main"):
# https://github.com/python/cpython/issues/89392
- raise Exception(f"Module {result.test_name} defines test_main() which is no longer supported by regrtest")
+ raise Exception(f"Module {test_name} defines test_main() which "
+ f"is no longer supported by regrtest")
def test_func():
return run_unittest(test_mod)
try:
- with save_env(result.test_name, runtests):
- regrtest_runner(result, test_func, runtests)
+ regrtest_runner(result, test_func, runtests)
finally:
# First kill any dangling references to open files etc.
# This can also issue some ResourceWarnings which would otherwise get
# failures.
support.gc_collect()
- remove_testfn(result.test_name, runtests.verbose)
+ remove_testfn(test_name, runtests.verbose)
if gc.garbage:
support.environment_altered = True
- print_warning(f"{result.test_name} created {len(gc.garbage)} "
+ print_warning(f"{test_name} created {len(gc.garbage)} "
f"uncollectable object(s)")
# move the uncollectable objects somewhere,
def _runtest_env_changed_exc(result: TestResult, runtests: RunTests,
display_failure: bool = True) -> None:
- # Detect environment changes, handle exceptions.
+ # Handle exceptions, detect environment changes.
# Reset the environment_altered flag to detect if a test altered
# the environment
clear_caches()
support.gc_collect()
- with save_env(test_name, runtests):
+ with 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: