[2.7] bpo-37359: Add --cleanup option to python3 -m test (GH-14332) by vstinner · Pull Request #14333 · python/cpython

Expand Up @@ -375,7 +375,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, 'runleaks', 'huntrleaks=', 'memlimit=', 'randseed=', 'multiprocess=', 'slaveargs=', 'forever', 'header', 'pgo', 'failfast', 'match=', 'testdir=', 'list-tests', 'list-cases', 'coverage', 'matchfile=', 'fail-env-changed']) 'coverage', 'matchfile=', 'fail-env-changed', 'cleanup']) except getopt.error, msg: usage(2, msg)
Expand All @@ -388,6 +388,7 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, list_tests = False list_cases_opt = False fail_env_changed = False cleanup_tests = False for o, a in opts: if o in ('-h', '--help'): usage(0) Expand Down Expand Up @@ -490,6 +491,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, list_cases_opt = True elif o == '--fail-env-changed': fail_env_changed = True elif o == '--cleanup': cleanup_tests = True else: print >>sys.stderr, ("No handler for option {}. Please " "report this as a bug at http://bugs.python.org.").format(o) Expand Down Expand Up @@ -527,6 +530,22 @@ def main(tests=None, testdir=None, verbose=0, quiet=False, print >>sys.stderr, msg sys.exit(2)
if cleanup_tests: import glob
os.chdir(support.SAVEDCWD) path = os.path.join(TEMPDIR, 'test_python_*') print("Cleanup %s directory" % TEMPDIR) for name in glob.glob(path): if os.path.isdir(name): print("Remove directory: %s" % name) support.rmtree(name) else: print("Remove file: %s" % name) support.unlink(name) sys.exit(0)

if slaveargs is not None: args, kwargs = json.loads(slaveargs) if testdir: Expand Down