From 32a60b6bf4027bb1ff9dfddb32c949b5ec49f97f Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Sun, 4 Nov 2018 07:53:50 -0800 Subject: [PATCH 1/3] Add --tempdir option for test run --- .azure-pipelines/windows-steps.yml | 2 +- Lib/test/libregrtest/cmdline.py | 6 +++--- Lib/test/libregrtest/main.py | 12 +++++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.azure-pipelines/windows-steps.yml b/.azure-pipelines/windows-steps.yml index d8d5f1753a0717..c3175841a9b857 100644 --- a/.azure-pipelines/windows-steps.yml +++ b/.azure-pipelines/windows-steps.yml @@ -17,7 +17,7 @@ steps: - script: python.bat -m test.pythoninfo displayName: 'Display build info' -- script: PCbuild\rt.bat -q -uall -u-cpu -rwW --slowest --timeout=1200 -j0 --junit-xml="$(Build.BinariesDirectory)\test-results.xml" +- script: PCbuild\rt.bat -q -uall -u-cpu -rwW --slowest --timeout=1200 -j0 --junit-xml="$(Build.BinariesDirectory)\test-results.xml" --tempdir="$(Build.BinariesDirectory)\test" displayName: 'Tests' env: PREFIX: $(Py_OutDir)\$(arch) diff --git a/Lib/test/libregrtest/cmdline.py b/Lib/test/libregrtest/cmdline.py index 538ff05489ea9a..09270323611f4e 100644 --- a/Lib/test/libregrtest/cmdline.py +++ b/Lib/test/libregrtest/cmdline.py @@ -271,7 +271,8 @@ def _create_parser(): group.add_argument('--junit-xml', dest='xmlpath', metavar='FILENAME', help='writes JUnit-style XML results to the specified ' 'file') - + group.add_argument('--tempdir', dest='tempdir', metavar='PATH', + help='override the working directory for the test run') return parser @@ -383,8 +384,7 @@ def _parse_args(args, **kwargs): if ns.match_filename: if ns.match_tests is None: ns.match_tests = [] - filename = os.path.join(support.SAVEDCWD, ns.match_filename) - with open(filename) as fp: + with open(ns.match_filename) as fp: for line in fp: ns.match_tests.append(line.strip()) diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index 1fd41320d11193..371ef707d413b1 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -37,7 +37,7 @@ TEMPDIR = sysconfig.get_config_var('srcdir') TEMPDIR = os.path.join(TEMPDIR, 'build') else: - TEMPDIR = tempfile.gettempdir() + TEMPDIR = os.getenv('PY_TEMPDIR', None) or tempfile.gettempdir() TEMPDIR = os.path.abspath(TEMPDIR) @@ -550,10 +550,14 @@ def save_xml_result(self): def main(self, tests=None, **kwargs): global TEMPDIR + self.ns = self.parse_args(kwargs) + + if self.ns.tempdir: + TEMPDIR = self.ns.tempdir - if sysconfig.is_python_build(): + if not os.path.isdir(TEMPDIR): try: - os.mkdir(TEMPDIR) + os.makedirs(TEMPDIR) except FileExistsError: pass @@ -571,8 +575,6 @@ def main(self, tests=None, **kwargs): self._main(tests, kwargs) def _main(self, tests, kwargs): - self.ns = self.parse_args(kwargs) - if self.ns.huntrleaks: warmup, repetitions, _ = self.ns.huntrleaks if warmup < 1 or repetitions < 1: From 994787a00a1d991a0a4968fb322069d2fea9c86b Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Sun, 4 Nov 2018 07:54:46 -0800 Subject: [PATCH 2/3] Remove envvar override --- Lib/test/libregrtest/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index 371ef707d413b1..357a2df010a60b 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -37,7 +37,7 @@ TEMPDIR = sysconfig.get_config_var('srcdir') TEMPDIR = os.path.join(TEMPDIR, 'build') else: - TEMPDIR = os.getenv('PY_TEMPDIR', None) or tempfile.gettempdir() + TEMPDIR = tempfile.gettempdir() TEMPDIR = os.path.abspath(TEMPDIR) From 7270516444e10676fea2f9247dd07bf642a7e281 Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Sat, 17 Nov 2018 11:08:56 +0000 Subject: [PATCH 3/3] Simplify call to create TEMPDIR --- Lib/test/libregrtest/main.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Lib/test/libregrtest/main.py b/Lib/test/libregrtest/main.py index 357a2df010a60b..a8d27ae5f332c6 100644 --- a/Lib/test/libregrtest/main.py +++ b/Lib/test/libregrtest/main.py @@ -555,11 +555,7 @@ def main(self, tests=None, **kwargs): if self.ns.tempdir: TEMPDIR = self.ns.tempdir - if not os.path.isdir(TEMPDIR): - try: - os.makedirs(TEMPDIR) - except FileExistsError: - pass + os.makedirs(TEMPDIR, exist_ok=True) # 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