[Python-checkins] bpo-37359: Add --cleanup option to python3 -m test (GH-14332) (GH-14333)

Victor Stinner webhook-mailer at python.org
Mon Jun 24 07:21:22 EDT 2019


https://github.com/python/cpython/commit/9d55bf440cd0b8b06509318d7676c0744147c5b2
commit: 9d55bf440cd0b8b06509318d7676c0744147c5b2
branch: 2.7
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2019-06-24T13:21:18+02:00
summary:

bpo-37359: Add --cleanup option to python3 -m test (GH-14332) (GH-14333)

* regrtest: Add --cleanup option to remove "test_python_*" directories
  of previous failed test jobs.
* Add "make cleantest" to run "python -m test --cleanup".

(cherry picked from commit 47fbc4e45b35b3111e2d947a66490a43ac21d363)

files:
A Misc/NEWS.d/next/Tests/2019-06-24-10-47-07.bpo-37359.CkdtyO.rst
M Lib/test/regrtest.py
M Makefile.pre.in

diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 046f6560a210..5b0b3e4422c0 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -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)
 
@@ -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)
@@ -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)
@@ -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:
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 9297e7fc89c4..2a14f3323bc3 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -855,6 +855,12 @@ $(LIBRARY_OBJS) $(MODOBJS) Modules/python.o: $(PYTHON_HEADERS)
 TESTOPTS=	-l $(EXTRATESTOPTS)
 TESTPROG=	$(srcdir)/Lib/test/regrtest.py
 TESTPYTHON=	$(RUNSHARED) ./$(BUILDPYTHON) -Wd -3 -E -tt $(TESTPYTHONOPTS)
+
+# Remove "test_python_*" directories of previous failed test jobs.
+# Pass TESTOPTS options because it can contain --tempdir option.
+cleantest: build_all
+	$(TESTPYTHON) $(TESTPROG) $(TESTOPTS) --cleanup
+
 test:		@DEF_MAKE_RULE@ platform
 		-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
 		-$(TESTPYTHON) $(TESTPROG) $(TESTOPTS)
diff --git a/Misc/NEWS.d/next/Tests/2019-06-24-10-47-07.bpo-37359.CkdtyO.rst b/Misc/NEWS.d/next/Tests/2019-06-24-10-47-07.bpo-37359.CkdtyO.rst
new file mode 100644
index 000000000000..3d5350de4f43
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2019-06-24-10-47-07.bpo-37359.CkdtyO.rst
@@ -0,0 +1,4 @@
+Add --cleanup option to python3 -m test to remove ``test_python_*``
+directories of previous failed jobs. Add "make cleantest" to run
+``python3 -m test --cleanup``.
+



More information about the Python-checkins mailing list