@@ -68,18 +68,14 @@ def regrtest_runner(result: TestResult, test_func, runtests: RunTests) -> None:
6868 result .stats = stats
6969
7070
71- def save_env (test_name : TestName , runtests : RunTests ):
72- return saved_test_environment (test_name , runtests .verbose , runtests .quiet ,
73- pgo = runtests .pgo )
74-
75-
7671# Storage of uncollectable GC objects (gc.garbage)
7772GC_GARBAGE = []
7873
7974
8075def _load_run_test (result : TestResult , runtests : RunTests ) -> None :
81- # Load the test function, run the test function.
82- module_name = abs_module_name (result .test_name , runtests .test_dir )
76+ # Load the test module and run the tests.
77+ test_name = result .test_name
78+ module_name = abs_module_name (test_name , runtests .test_dir )
8379
8480 # Remove the module from sys.module to reload it if it was already imported
8581 sys .modules .pop (module_name , None )
@@ -88,25 +84,25 @@ def _load_run_test(result: TestResult, runtests: RunTests) -> None:
8884
8985 if hasattr (test_mod , "test_main" ):
9086 # https://github.com/python/cpython/issues/89392
91- raise Exception (f"Module { result .test_name } defines test_main() which is no longer supported by regrtest" )
87+ raise Exception (f"Module { test_name } defines test_main() which "
88+ f"is no longer supported by regrtest" )
9289 def test_func ():
9390 return run_unittest (test_mod )
9491
9592 try :
96- with save_env (result .test_name , runtests ):
97- regrtest_runner (result , test_func , runtests )
93+ regrtest_runner (result , test_func , runtests )
9894 finally :
9995 # First kill any dangling references to open files etc.
10096 # This can also issue some ResourceWarnings which would otherwise get
10197 # triggered during the following test run, and possibly produce
10298 # failures.
10399 support .gc_collect ()
104100
105- remove_testfn (result . test_name , runtests .verbose )
101+ remove_testfn (test_name , runtests .verbose )
106102
107103 if gc .garbage :
108104 support .environment_altered = True
109- print_warning (f"{ result . test_name } created { len (gc .garbage )} "
105+ print_warning (f"{ test_name } created { len (gc .garbage )} "
110106 f"uncollectable object(s)" )
111107
112108 # move the uncollectable objects somewhere,
@@ -119,7 +115,7 @@ def test_func():
119115
120116def _runtest_env_changed_exc (result : TestResult , runtests : RunTests ,
121117 display_failure : bool = True ) -> None :
122- # Detect environment changes, handle exceptions .
118+ # Handle exceptions, detect environment changes .
123119
124120 # Reset the environment_altered flag to detect if a test altered
125121 # the environment
@@ -135,7 +131,8 @@ def _runtest_env_changed_exc(result: TestResult, runtests: RunTests,
135131 clear_caches ()
136132 support .gc_collect ()
137133
138- with save_env (test_name , runtests ):
134+ with saved_test_environment (test_name ,
135+ runtests .verbose , quiet , pgo = pgo ):
139136 _load_run_test (result , runtests )
140137 except support .ResourceDenied as msg :
141138 if not quiet and not pgo :
0 commit comments