Skip to content

Commit fd67616

Browse files
committed
pythongh-109276: libregrtest only checks saved_test_environment() once (python#109278)
There is no need to check for environment changes twice.
1 parent 48ff3d3 commit fd67616

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

Lib/test/libregrtest/save_env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class saved_test_environment:
3636
items is also printed.
3737
"""
3838

39-
def __init__(self, test_name, verbose=0, quiet=False, *, pgo=False):
39+
def __init__(self, test_name, verbose, quiet, *, pgo):
4040
self.test_name = test_name
4141
self.verbose = verbose
4242
self.quiet = quiet

Lib/test/libregrtest/single.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
7772
GC_GARBAGE = []
7873

7974

8075
def _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

120116
def _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

Comments
 (0)