Bug 1388013 - Support running |mach python-test| against Python 3 draft
authorDave Hunt <dhunt@mozilla.com>
Wed, 16 Aug 2017 11:25:20 +0100
changeset 647556 a8a17d13701f61948162be62ace1e2012b13e599
parent 647555 3955a05c610d26cce72aa7860cafcf72c07999d1
child 726538 1a4e14c345fa07de6979ea31c9f5324d283128d4
push id74442
push userbmo:dave.hunt@gmail.com
push dateWed, 16 Aug 2017 14:37:14 +0000
bugs1388013
milestone57.0a1
Bug 1388013 - Support running |mach python-test| against Python 3 MozReview-Commit-ID: 6LAiNiHD5Wx
python/mach_commands.py
--- a/python/mach_commands.py
+++ b/python/mach_commands.py
@@ -61,16 +61,20 @@ class MachCommands(MachCommandBase):
     @CommandArgument('-j', '--jobs',
         default=1,
         type=int,
         help='Number of concurrent jobs to run. Default is 1.')
     @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('--py3',
+        default=False,
+        action='store_true',
+        help='Run tests against Python 3.')
     @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, *args, **kwargs):
         try:
             tempdir = os.environ[b'PYTHON_TEST_TMP'] = str(tempfile.mkdtemp(suffix='-python-test'))
             return self.run_python_tests(*args, **kwargs)
@@ -79,18 +83,25 @@ class MachCommands(MachCommandBase):
             mozfile.remove(tempdir)
 
     def run_python_tests(self,
                          tests=[],
                          test_objects=None,
                          subsuite=None,
                          verbose=False,
                          stop=False,
-                         jobs=1):
-        self._activate_virtualenv()
+                         jobs=1,
+                         py3=False):
+        if py3:
+            _py3_path = '/Users/dhunt/.pyenv/versions/3.6.2/bin/python'
+            self.virtualenv_manager.virtualenv_root += '_py3'
+            self.virtualenv_manager.ensure(python=_py3_path)
+            self.virtualenv_manager.activate()
+        else:
+            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)
                 elif os.path.isdir(t):
@@ -126,17 +137,24 @@ class MachCommands(MachCommandBase):
         mp.tests.extend(test_objects)
 
         if not mp.tests:
             message = 'TEST-UNEXPECTED-FAIL | No tests collected ' + \
                       '(Not in PYTHON_UNITTEST_MANIFESTS?)'
             self.log(logging.WARN, 'python-test', {}, message)
             return 1
 
+        def _py3(tests, values):
+            for test in tests:
+                if 'py3' in test:
+                    yield test
+
         filters = []
+        if py3:
+            filters.append(_py3)
         if subsuite == 'default':
             filters.append(mpf.subsuite(None))
         elif subsuite:
             filters.append(mpf.subsuite(subsuite))
 
         tests = mp.active_tests(filters=filters, disabled=False, **mozinfo.info)
         parallel = []
         sequential = []