Commit 8767de2f authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-30759: regrtest: list_cases() now unload modules (#2582)

list_cases() now unload modules, as the test runner does, to prevent
a failure in test_xpickle about test.pickletester loaded after
loading test_cpickle:

./python -m test --list-cases test_cpickle test_xpickle
parent 668489a6
...@@ -289,6 +289,13 @@ def format_test_result(test_name, result): ...@@ -289,6 +289,13 @@ def format_test_result(test_name, result):
return fmt % test_name return fmt % test_name
def unload_test_modules(save_modules):
# Unload the newly imported modules (best effort finalization)
for module in sys.modules.keys():
if module not in save_modules and module.startswith("test."):
test_support.unload(module)
def main(tests=None, testdir=None, verbose=0, quiet=False, def main(tests=None, testdir=None, verbose=0, quiet=False,
exclude=False, single=False, randomize=False, fromfile=None, exclude=False, single=False, randomize=False, fromfile=None,
findleaks=False, use_resources=None, trace=False, coverdir='coverage', findleaks=False, use_resources=None, trace=False, coverdir='coverage',
...@@ -835,10 +842,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, ...@@ -835,10 +842,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
# them again # them again
found_garbage.extend(gc.garbage) found_garbage.extend(gc.garbage)
del gc.garbage[:] del gc.garbage[:]
# Unload the newly imported modules (best effort finalization)
for module in sys.modules.keys(): unload_test_modules(save_modules)
if module not in save_modules and module.startswith("test."):
test_support.unload(module)
if interrupted and not pgo: if interrupted and not pgo:
# print a newline after ^C # print a newline after ^C
...@@ -1543,6 +1548,7 @@ def list_cases(testdir, selected, match_tests): ...@@ -1543,6 +1548,7 @@ def list_cases(testdir, selected, match_tests):
test_support.verbose = False test_support.verbose = False
test_support.match_tests = match_tests test_support.match_tests = match_tests
save_modules = set(sys.modules)
skipped = [] skipped = []
for test in selected: for test in selected:
abstest = get_abs_module(testdir, test) abstest = get_abs_module(testdir, test)
...@@ -1552,6 +1558,8 @@ def list_cases(testdir, selected, match_tests): ...@@ -1552,6 +1558,8 @@ def list_cases(testdir, selected, match_tests):
except unittest.SkipTest: except unittest.SkipTest:
skipped.append(test) skipped.append(test)
unload_test_modules(save_modules)
if skipped: if skipped:
print >>sys.stderr print >>sys.stderr
print >>sys.stderr, count(len(skipped), "test"), "skipped:" print >>sys.stderr, count(len(skipped), "test"), "skipped:"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment