summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2010-12-03 10:42:03 (GMT)
committerMichael Foord <fuzzyman@voidspace.org.uk>2010-12-03 10:42:03 (GMT)
commitee4a5e0ca892e44a85b95c75b33524ea941768fe (patch)
tree0e41bfe1de3d2a01e5ae1a1b1f88a97ea669692e
parent9bd45f995fa7e79edaf6e79f947de70c22e00168 (diff)
downloadcpython-ee4a5e0ca892e44a85b95c75b33524ea941768fe.zip
cpython-ee4a5e0ca892e44a85b95c75b33524ea941768fe.tar.gz
cpython-ee4a5e0ca892e44a85b95c75b33524ea941768fe.tar.bz2
Adding lib/test/__main__.py for running tests with 'python -m test'
-rw-r--r--Lib/test/__main__.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/Lib/test/__main__.py b/Lib/test/__main__.py
new file mode 100644
index 0000000..251ac7c
--- /dev/null
+++ b/Lib/test/__main__.py
@@ -0,0 +1,40 @@
+import os
+import sys
+import sysconfig
+
+from test import support
+from test import regrtest
+
+# 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)
+regrtest.TESTCWD = TESTCWD
+
+# 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
+# change the CWD, the original CWD will be used. The original CWD is
+# available from support.SAVEDCWD.
+with support.temp_cwd(TESTCWD, quiet=True):
+ regrtest.main()