Skip to content

gh-109276: libregrtest only checks saved_test_environment() once #109278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/save_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class saved_test_environment:
items is also printed.
"""

def __init__(self, test_name, verbose=0, quiet=False, *, pgo=False):
def __init__(self, test_name, verbose, quiet, *, pgo):
self.test_name = test_name
self.verbose = verbose
self.quiet = quiet
Expand Down
25 changes: 11 additions & 14 deletions Lib/test/libregrtest/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,14 @@ def regrtest_runner(result: TestResult, test_func, runtests: RunTests) -> None:
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)
Expand All @@ -88,25 +84,25 @@ def _load_run_test(result: TestResult, runtests: RunTests) -> 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
# triggered during the following test run, and possibly produce
# 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,
Expand All @@ -119,7 +115,7 @@ def test_func():

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
Expand All @@ -135,7 +131,8 @@ def _runtest_env_changed_exc(result: TestResult, runtests: RunTests,
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:
Expand Down