Bug 1048446 - [python-test] Set up a temporary directory for tests to use, r?gbrown
We set up the temporary directory here so that it persists across multiple test invocations, as each
test is run in its own subprocess.
MozReview-Commit-ID: 7SNip54AqEI
--- a/python/mach_commands.py
+++ b/python/mach_commands.py
@@ -1,29 +1,30 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import, print_function, unicode_literals
import argparse
import logging
-import mozpack.path as mozpath
import os
+import tempfile
from concurrent.futures import (
ThreadPoolExecutor,
as_completed,
thread,
)
import mozinfo
from manifestparser import TestManifest
from manifestparser import filters as mpf
+import mozpack.path as mozpath
from mozbuild.base import (
MachCommandBase,
)
from mach.decorators import (
CommandArgument,
CommandProvider,
Command,
@@ -64,23 +65,31 @@ class MachCommands(MachCommandBase):
@CommandArgument('--subsuite',
default=None,
help=('Python subsuite to run. If not specified, all subsuites are run. '
'Use the string `default` to only run tests without a subsuite.'))
@CommandArgument('tests', nargs='*',
metavar='TEST',
help=('Tests to run. Each test can be a single file or a directory. '
'Default test resolution relies on PYTHON_UNITTEST_MANIFESTS.'))
- def python_test(self,
- tests=[],
- test_objects=None,
- subsuite=None,
- verbose=False,
- stop=False,
- jobs=1):
+ def python_test(self, *args, **kwargs):
+ try:
+ tempdir = os.environ[b'PYTHON_TEST_TMP'] = str(tempfile.mkdtemp(suffix='-python-test'))
+ return self.run_python_tests(*args, **kwargs)
+ finally:
+ import mozfile
+ mozfile.remove(tempdir)
+
+ def run_python_tests(self,
+ tests=[],
+ test_objects=None,
+ subsuite=None,
+ verbose=False,
+ stop=False,
+ jobs=1):
self._activate_virtualenv()
def find_tests_by_path():
import glob
files = []
for t in tests:
if t.endswith('.py') and os.path.isfile(t):
files.append(t)