[Python-checkins] r86968 - in python/branches/py3k: Lib/test/__main__.py Lib/test/regrtest.py Misc/NEWS

michael.foord python-checkins at python.org
Fri Dec 3 13:27:40 CET 2010


Author: michael.foord
Date: Fri Dec  3 13:27:40 2010
New Revision: 86968

Log:
Factor out common code from lib/test/__main__.py and lib/test/regrtest.py into a function.

Modified:
   python/branches/py3k/Lib/test/__main__.py
   python/branches/py3k/Lib/test/regrtest.py
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Lib/test/__main__.py
==============================================================================
--- python/branches/py3k/Lib/test/__main__.py	(original)
+++ python/branches/py3k/Lib/test/__main__.py	Fri Dec  3 13:27:40 2010
@@ -1,37 +1,8 @@
-import os
-import sys
-import sysconfig
+from test import regrtest, support
 
-from test import support
-from test import regrtest
 
-TEMPDIR = regrtest.TEMPDIR
-
-# findtestdir() gets the dirname out of __file__, so we have to make it
-# absolute before changing the working directory.
-# For example __file__ may be relative when running trace or profile.
-# See issue #9323.
-__file__ = os.path.abspath(__file__)
-
-# sanity check
-assert __file__ == os.path.abspath(sys.argv[0])
-
-# When tests are run from the Python build directory, it is best practice
-# to keep the test files in a subfolder.  It eases the cleanup of leftover
-# files using command "make distclean".
-if sysconfig.is_python_build():
-    TEMPDIR = os.path.join(sysconfig.get_config_var('srcdir'), 'build')
-    TEMPDIR = os.path.abspath(TEMPDIR)
-    if not os.path.exists(TEMPDIR):
-        os.mkdir(TEMPDIR)
-    regrtest.TEMPDIR = TEMPDIR
-
-# Define a writable temp dir that will be used as cwd while running
-# the tests. The name of the dir includes the pid to allow parallel
-# testing (see the -j option).
-TESTCWD = 'test_python_{}'.format(os.getpid())
-
-TESTCWD = os.path.join(TEMPDIR, TESTCWD)
+TEMPDIR, TESTCWD = regrtest._make_temp_dir_for_build(regrtest.TEMPDIR)
+regrtest.TEMPDIR = TEMPDIR
 regrtest.TESTCWD = TESTCWD
 
 # Run the tests in a context manager that temporary changes the CWD to a

Modified: python/branches/py3k/Lib/test/regrtest.py
==============================================================================
--- python/branches/py3k/Lib/test/regrtest.py	(original)
+++ python/branches/py3k/Lib/test/regrtest.py	Fri Dec  3 13:27:40 2010
@@ -1468,6 +1468,23 @@
         assert self.isvalid()
         return self.expected
 
+def _make_temp_dir_for_build(TEMPDIR):
+    # When tests are run from the Python build directory, it is best practice
+    # to keep the test files in a subfolder.  It eases the cleanup of leftover
+    # files using command "make distclean".
+    if sysconfig.is_python_build():
+        TEMPDIR = os.path.join(sysconfig.get_config_var('srcdir'), 'build')
+        TEMPDIR = os.path.abspath(TEMPDIR)
+        if not os.path.exists(TEMPDIR):
+            os.mkdir(TEMPDIR)
+
+    # Define a writable temp dir that will be used as cwd while running
+    # the tests. The name of the dir includes the pid to allow parallel
+    # testing (see the -j option).
+    TESTCWD = 'test_python_{}'.format(os.getpid())
+
+    TESTCWD = os.path.join(TEMPDIR, TESTCWD)
+    return TEMPDIR, TESTCWD
 
 if __name__ == '__main__':
     # Remove regrtest.py's own directory from the module search path. Despite
@@ -1491,21 +1508,7 @@
     # sanity check
     assert __file__ == os.path.abspath(sys.argv[0])
 
-    # When tests are run from the Python build directory, it is best practice
-    # to keep the test files in a subfolder.  It eases the cleanup of leftover
-    # files using command "make distclean".
-    if sysconfig.is_python_build():
-        TEMPDIR = os.path.join(sysconfig.get_config_var('srcdir'), 'build')
-        TEMPDIR = os.path.abspath(TEMPDIR)
-        if not os.path.exists(TEMPDIR):
-            os.mkdir(TEMPDIR)
-
-    # Define a writable temp dir that will be used as cwd while running
-    # the tests. The name of the dir includes the pid to allow parallel
-    # testing (see the -j option).
-    TESTCWD = 'test_python_{}'.format(os.getpid())
-
-    TESTCWD = os.path.join(TEMPDIR, TESTCWD)
+    TEMPDIR, TESTCWD = _make_temp_dir_for_build(TEMPDIR)
 
     # Run the tests in a context manager that temporary changes the CWD to a
     # temporary and writable directory. If it's not possible to create or

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Fri Dec  3 13:27:40 2010
@@ -206,6 +206,9 @@
 - regrtest.py once again ensures the test directory is removed from sys.path
   when it is invoked directly as the __main__ module
 
+- `python -m test` can be used to run the test suite as well as
+  `python -m test.regrtest`.
+
 - Issue #9424: Deprecate the `unittest.TestCase` methods `assertEquals`,
   `assertNotEquals`, `assertAlmostEquals`, `assertNotAlmostEquals` and `assert_`
   and replace them with the correct methods in the Python test suite.


More information about the Python-checkins mailing list