diff options
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/test/regrtest.py | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index ca4a3b5..023ad9a 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -496,14 +496,30 @@ def findtests(testdir=None, stdtests=STDTESTS, nottests=NOTTESTS): def runtest(test, generate, verbose, quiet, testdir=None, huntrleaks=False): """Run a single test. + test -- the name of the test generate -- if true, generate output, instead of running the test - and comparing it to a previously created output file + and comparing it to a previously created output file verbose -- if true, print more messages quiet -- if true, don't print 'skipped' messages (probably redundant) testdir -- test directory + huntrleaks -- run multiple times to test for leaks; requires a debug + build; a triple corresponding to -R's three arguments + Return: + -2 test skipped because resource denied + -1 test skipped for some other reason + 0 test failed + 1 test passed """ + try: + return runtest_inner(test, generate, verbose, quiet, testdir, + huntrleaks) + finally: + cleanup_test_droppings(test, verbose) + +def runtest_inner(test, generate, verbose, quiet, + testdir=None, huntrleaks=False): test_support.unload(test) if not testdir: testdir = findtestdir() @@ -595,6 +611,37 @@ def runtest(test, generate, verbose, quiet, testdir=None, huntrleaks=False): sys.stdout.flush() return 0 +def cleanup_test_droppings(testname, verbose): + import shutil + + # Try to clean up junk commonly left behind. While tests shouldn't leave + # any files or directories behind, when a test fails that can be tedious + # for it to arrange. The consequences can be especially nasty on Windows, + # since if a test leaves a file open, it cannot be deleted by name (while + # there's nothing we can do about that here either, we can display the + # name of the offending test, which is a real help). + for name in (test_support.TESTFN, + "db_home", + ): + if not os.path.exists(name): + continue + + if os.path.isdir(name): + kind, nuker = "directory", shutil.rmtree + elif os.path.isfile(name): + kind, nuker = "file", os.unlink + else: + raise SystemError("os.path says %r exists but is neither " + "directory nor file" % name) + + if verbose: + print "%r left behind %s %r" % (testname, kind, name) + try: + nuker(name) + except Exception, msg: + print >> sys.stderr, ("%r left behind %s %r and it couldn't be " + "removed: %s" % (testname, kind, name, msg)) + def dash_R(the_module, test, indirect_test, huntrleaks): # This code is hackish and inelegant, but it seems to do the job. import copy_reg |