Bug 1466211 - Use --python for selecting target Python when using |mach python-test|; r=ahal
☠☠ backed out by bfde37aecadd ☠ ☠
authorDave Hunt <dhunt@mozilla.com>
Wed, 13 Jun 2018 14:18:21 -0700
changeset 480074 dfdf4ea83655c4663c5b75f5d096e5ebb75f7fed
parent 480073 23eb377e2e6d12ecf1ceb2c8e58fc41ccf89896f
child 480075 6680ca0acc27c781a81cbf89885d5bac2a13a5c0
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs1466211
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1466211 - Use --python for selecting target Python when using |mach python-test|; r=ahal MozReview-Commit-ID: J8DSmX8mItb
python/mach_commands.py
python/mozbuild/mozbuild/virtualenv.py
--- a/python/mach_commands.py
+++ b/python/mach_commands.py
@@ -62,20 +62,20 @@ class MachCommands(MachCommandBase):
                                 append_env=append_env)
 
     @Command('python-test', category='testing',
              description='Run Python unit tests with an appropriate test runner.')
     @CommandArgument('-v', '--verbose',
                      default=False,
                      action='store_true',
                      help='Verbose output.')
-    @CommandArgument('--three',
-                     default=False,
-                     action='store_true',
-                     help='Run tests using Python 3.')
+    @CommandArgument('--python',
+                     help='Version of Python for Pipenv to use. When given a '
+                          'Python version, Pipenv will automatically scan your '
+                          'system for a Python that matches that given version.')
     @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.'))
@@ -92,20 +92,20 @@ class MachCommands(MachCommandBase):
             mozfile.remove(tempdir)
 
     def run_python_tests(self,
                          tests=None,
                          test_objects=None,
                          subsuite=None,
                          verbose=False,
                          jobs=1,
-                         three=False,
+                         python=None,
                          **kwargs):
-        pipenv_args = ['--three' if three else '--two']
-        self.activate_pipenv(pipfile=None, args=pipenv_args, populate=True)
+        python = python or self.virtualenv_manager.python_path
+        self.activate_pipenv(pipfile=None, args=['--python', python], populate=True)
 
         if test_objects is None:
             from moztest.resolve import TestResolver
             resolver = self._spawn(TestResolver)
             # If we were given test paths, try to find tests matching them.
             test_objects = resolver.resolve_tests(paths=tests, flavor='python')
         else:
             # We've received test_objects from |mach test|. We need to ignore
@@ -117,18 +117,21 @@ class MachCommands(MachCommandBase):
         mp.tests.extend(test_objects)
 
         filters = []
         if subsuite == 'default':
             filters.append(mpf.subsuite(None))
         elif subsuite:
             filters.append(mpf.subsuite(subsuite))
 
-        python = 3 if three else 2
-        tests = mp.active_tests(filters=filters, disabled=False, python=python, **mozinfo.info)
+        tests = mp.active_tests(
+            filters=filters,
+            disabled=False,
+            python=self.virtualenv_manager.version_info[0],
+            **mozinfo.info)
 
         if not tests:
             submsg = "for subsuite '{}' ".format(subsuite) if subsuite else ""
             message = "TEST-UNEXPECTED-FAIL | No tests collected " + \
                       "{}(Not in PYTHON_UNITTEST_MANIFESTS?)".format(submsg)
             self.log(logging.WARN, 'python-test', {}, message)
             return 1
 
--- a/python/mozbuild/mozbuild/virtualenv.py
+++ b/python/mozbuild/mozbuild/virtualenv.py
@@ -88,16 +88,21 @@ class VirtualenvManager(object):
     def python_path(self):
         binary = 'python'
         if sys.platform in ('win32', 'cygwin'):
             binary += '.exe'
 
         return os.path.join(self.bin_path, binary)
 
     @property
+    def version_info(self):
+        return eval(subprocess.check_output([
+            self.python_path, '-c', 'import sys; print(sys.version_info[:])']))
+
+    @property
     def activate_path(self):
         return os.path.join(self.bin_path, 'activate_this.py')
 
     def get_exe_info(self):
         """Returns the version and file size of the python executable that was in
         use when this virutalenv was created.
         """
         with open(self.exe_info_path, 'r') as fh: