diff -r adb6b029b102 Lib/test/__init__.py --- a/Lib/test/__init__.py Wed Mar 09 15:02:31 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -# Dummy file to make this directory a package. diff -r adb6b029b102 Lib/test/libregrtest/setup.py --- a/Lib/test/libregrtest/setup.py Wed Mar 09 15:02:31 2016 +0100 +++ b/Lib/test/libregrtest/setup.py Fri Mar 11 12:53:50 2016 +0100 @@ -29,6 +29,9 @@ def setup_tests(ns): replace_stdout() support.record_original_stdout(sys.stdout) + if ns.testdir: + sys.path.insert(0, os.path.dirname(ns.testdir)) + # Some times __path__ and __file__ are not absolute (e.g. while running from # Lib/) and, if we change the CWD to run the tests in a temporary dir, some # imports might fail. This affects only the modules imported before os.chdir(). diff -r adb6b029b102 Lib/test/test_regrtest.py --- a/Lib/test/test_regrtest.py Wed Mar 09 15:02:31 2016 +0100 +++ b/Lib/test/test_regrtest.py Fri Mar 11 12:53:50 2016 +0100 @@ -15,6 +15,7 @@ import re import subprocess import sys import sysconfig +import tempfile import textwrap import unittest from test import libregrtest @@ -306,9 +307,18 @@ class BaseTestCase(unittest.TestCase): TESTNAME_PREFIX = 'test_regrtest_' TESTNAME_REGEX = r'test_[a-z0-9_]+' + def create_testdir(self): + self.tmpdir = tempfile.mkdtemp() + self.addCleanup(support.rmtree, self.tmpdir) + + self.tmptestdir = os.path.join(self.tmpdir, 'test') + os.mkdir(self.tmptestdir) + def setUp(self): self.testdir = os.path.realpath(os.path.dirname(__file__)) + self.create_testdir() + # When test_regrtest is interrupted by CTRL+c, it can leave # temporary test files remove = [entry.path @@ -327,7 +337,7 @@ class BaseTestCase(unittest.TestCase): # test_regrtest cannot be run twice in parallel because # of setUp() and create_test() name = self.TESTNAME_PREFIX + "%s_%s" % (os.getpid(), name) - path = os.path.join(self.testdir, name + '.py') + path = os.path.join(self.tmptestdir, name + '.py') self.addCleanup(support.unlink, path) # Use 'x' mode to ensure that we do not override existing tests @@ -441,7 +451,9 @@ class BaseTestCase(unittest.TestCase): def run_python(self, args, **kw): - args = [sys.executable, '-X', 'faulthandler', '-I', *args] + args = [sys.executable, '-X', 'faulthandler', + #'-I', + *args] proc = self.run_command(args, **kw) return proc.stdout @@ -461,7 +473,7 @@ class ProgramsTestCase(BaseTestCase): self.tests = [self.create_test() for index in range(self.NTEST)] self.python_args = ['-Wd', '-E', '-bb'] - self.regrtest_args = ['-uall', '-rwW'] + self.regrtest_args = ['-uall', '-rwW', '--testdir=%s' % self.tmptestdir] if hasattr(faulthandler, 'dump_traceback_later'): self.regrtest_args.extend(('--timeout', '3600', '-j4')) if sys.platform == 'win32': @@ -518,7 +530,8 @@ class ProgramsTestCase(BaseTestCase): def test_tools_script_run_tests(self): # Tools/scripts/run_tests.py script = os.path.join(ROOT_DIR, 'Tools', 'scripts', 'run_tests.py') - self.run_tests([script, *self.tests]) + args = [script, '--testdir=%s' % self.tmptestdir, *self.tests] + self.run_tests(args) def run_batch(self, *args): proc = self.run_command(args) @@ -554,8 +567,9 @@ class ArgsTestCase(BaseTestCase): Test arguments of the Python test suite. """ - def run_tests(self, *args, **kw): - return self.run_python(['-m', 'test', *args], **kw) + def run_tests(self, *testargs, **kw): + cmdargs = ['-m', 'test', '--testdir=%s' % self.tmptestdir, *testargs] + return self.run_python(cmdargs, **kw) def test_failing_test(self): # test a failing test