Bug 1231981 - Part 5: Install python packages we need in the virtualenv if not present. r=gps draft
authorByron Campen [:bwc] <docfaraday@gmail.com>
Wed, 16 Mar 2016 15:40:17 -0500
changeset 356508 8907db56eb0c69b6884048562a99b4ccfd32f240
parent 356507 7281bcde96d166957804f98c0a307c5e4e05f817
child 356509 b0ae765b851acd3a354533b7bb7517dce4f7c4f8
push id16533
push userbcampen@mozilla.com
push dateTue, 26 Apr 2016 14:37:37 +0000
reviewersgps
bugs1231981
milestone49.0a1
Bug 1231981 - Part 5: Install python packages we need in the virtualenv if not present. r=gps MozReview-Commit-ID: 9PUHLMxHhQP
python/mozbuild/mozbuild/virtualenv.py
testing/mochitest/mach_commands.py
testing/mochitest/runtests.py
--- a/python/mozbuild/mozbuild/virtualenv.py
+++ b/python/mozbuild/mozbuild/virtualenv.py
@@ -457,16 +457,27 @@ class VirtualenvManager(object):
         virtualenv, you can simply instantiate an instance of this class
         and call .ensure() and .activate() to make the virtualenv active.
         """
 
         execfile(self.activate_path, dict(__file__=self.activate_path))
         if isinstance(os.environ['PATH'], unicode):
             os.environ['PATH'] = os.environ['PATH'].encode('utf-8')
 
+    def install_pip_requirements_file(self, requirements_filename):
+        """Installs packages in |requirements_filename| via pip."""
+
+        args = [
+            'install',
+            '-r',
+            requirements_filename
+        ]
+
+        return self._run_pip(args)
+
     def install_pip_package(self, package):
         """Install a package via pip.
 
         The supplied package is specified using a pip requirement specifier.
         e.g. 'foo' or 'foo==1.0'.
 
         If the package is already installed, this is a no-op.
         """
--- a/testing/mochitest/mach_commands.py
+++ b/testing/mochitest/mach_commands.py
@@ -150,16 +150,22 @@ class MochitestRunner(MozbuildObject):
 
         self.tests_dir = os.path.join(self.topobjdir, '_tests')
         self.mochitest_dir = os.path.join(
             self.tests_dir,
             'testing',
             'mochitest')
         self.bin_dir = os.path.join(self.topobjdir, 'dist', 'bin')
 
+        self._activate_virtualenv()
+        self.virtualenv_manager.install_pip_requirements_file(
+                os.path.join(self.mochitest_dir,
+                             'websocketprocessbridge',
+                             'websocketprocessbridge_requirements.txt'))
+
     def resolve_tests(self, test_paths, test_objects=None, cwd=None):
         if test_objects:
             return test_objects
 
         from mozbuild.testing import TestResolver
         resolver = self._spawn(TestResolver)
         tests = list(resolver.resolve_tests(paths=test_paths, cwd=cwd))
         return tests
--- a/testing/mochitest/runtests.py
+++ b/testing/mochitest/runtests.py
@@ -810,16 +810,17 @@ class MochitestBase(object):
     def startWebsocketProcessBridge(self, options):
         """Create a websocket server that can launch various processes that
         JS needs (eg; ICE server for webrtc testing)
         """
 
         command = [sys.executable,
                    os.path.join("websocketprocessbridge",
                                 "websocketprocessbridge.py")]
+        os.environ['PYTHONPATH'] = os.pathsep.join(p for p in sys.path)
         self.websocketprocessbridge = mozprocess.ProcessHandler(command,
                                                                 cwd=SCRIPT_DIR)
         self.websocketprocessbridge.run()
         self.log.info("runtests.py | websocket/process bridge pid: %d"
                       % self.websocketprocessbridge.pid)
 
         # ensure the server is up, wait for at most ten seconds
         for i in range(1,100):