Bug 975169 - Marionette test runner should not override textrunnerclass, version bump, r=jgriffiin,dburns
☠☠ backed out by a3e92264b4eb ☠ ☠
authorMalini Das <mdas@mozilla.com>
Mon, 24 Feb 2014 12:11:08 -0500
changeset 170560 2b3bda5a4744864bacbbdcba9bb9fe0e9e3d1b26
parent 170559 95325311fa2ef3e1a633f990b5adeb6d67650c91
child 170561 ba82c75ac11c978784adc5cea92890cf255eb7b8
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersjgriffiin, dburns
bugs975169
milestone30.0a1
Bug 975169 - Marionette test runner should not override textrunnerclass, version bump, r=jgriffiin,dburns
testing/marionette/client/marionette/runner/base.py
testing/marionette/client/setup.py
--- a/testing/marionette/client/marionette/runner/base.py
+++ b/testing/marionette/client/marionette/runner/base.py
@@ -37,20 +37,26 @@ class MarionetteTest(TestResult):
 
 class MarionetteTestResult(unittest._TextTestResult, TestResultCollection):
 
     resultClass = MarionetteTest
 
     def __init__(self, *args, **kwargs):
         self.marionette = kwargs.pop('marionette')
         TestResultCollection.__init__(self, 'MarionetteTest')
-        unittest._TextTestResult.__init__(self, *args, **kwargs)
         self.passed = 0
         self.testsRun = 0
         self.result_modifiers = [] # used by mixins to modify the result
+        pid = kwargs.pop('b2g_pid')
+        if pid:
+            bases = [b for b in self.__class__.__bases__]
+            bases.append(B2GTestResultMixin)
+            self.__class__.__bases__ = tuple(bases)
+            B2GTestResultMixin.__init__(self, b2g_pid=pid)
+        unittest._TextTestResult.__init__(self, *args, **kwargs)
 
     @property
     def skipped(self):
         return [t for t in self if t.result == 'SKIPPED']
 
     @skipped.setter
     def skipped(self, value):
         pass
@@ -235,27 +241,40 @@ class MarionetteTestResult(unittest._Tex
 
 class MarionetteTextTestRunner(unittest.TextTestRunner):
 
     resultclass = MarionetteTestResult
 
     def __init__(self, **kwargs):
         self.marionette = kwargs['marionette']
         self.capabilities = kwargs.pop('capabilities')
+        self.pre_run_functions = []
+        self.b2g_pid = None
         del kwargs['marionette']
+
+        if self.capabilities['device'] != 'desktop' and self.capabilities['b2g']:
+            def b2g_pre_run():
+                dm_type = os.environ.get('DM_TRANS', 'adb')
+                if dm_type == 'adb':
+                    self.b2g_pid = get_b2g_pid(get_dm(self.marionette))
+            self.pre_run_functions.append(b2g_pre_run)
+
         unittest.TextTestRunner.__init__(self, **kwargs)
 
     def _makeResult(self):
         return self.resultclass(self.stream,
                                 self.descriptions,
                                 self.verbosity,
-                                marionette=self.marionette)
+                                marionette=self.marionette,
+                                b2g_pid=self.b2g_pid)
 
     def run(self, test):
         "Run the given test case or test suite."
+        for pre_run_func in self.pre_run_functions:
+            pre_run_func()
         result = self._makeResult()
         if hasattr(self, 'failfast'):
             result.failfast = self.failfast
         if hasattr(self, 'buffer'):
             result.buffer = self.buffer
         startTime = time.time()
         startTestRun = getattr(result, 'startTestRun', None)
         if startTestRun is not None:
@@ -306,50 +325,16 @@ class MarionetteTextTestRunner(unittest.
             infos.append("unexpected successes=%d" % unexpectedSuccesses)
         if infos:
             self.stream.writeln(" (%s)" % (", ".join(infos),))
         else:
             self.stream.write("\n")
         return result
 
 
-class B2GMarionetteTestResult(MarionetteTestResult, B2GTestResultMixin):
-
-    def __init__(self, *args, **kwargs):
-        # stupid hack because _TextTestRunner doesn't accept **kwargs
-        b2g_pid = kwargs.pop('b2g_pid')
-        MarionetteTestResult.__init__(self, *args, **kwargs)
-        kwargs['b2g_pid'] = b2g_pid
-        B2GTestResultMixin.__init__(self, *args, **kwargs)
- 
-
-class B2GMarionetteTextTestRunner(MarionetteTextTestRunner):
-
-    resultclass = B2GMarionetteTestResult
-
-    def __init__(self, **kwargs):
-        MarionetteTextTestRunner.__init__(self, **kwargs)
-        if self.capabilities['device'] != 'desktop':
-            self.resultclass = B2GMarionetteTestResult
-        self.b2g_pid = None
-
-    def _makeResult(self):
-        return self.resultclass(self.stream,
-                                self.descriptions,
-                                self.verbosity,
-                                marionette=self.marionette,
-                                b2g_pid=self.b2g_pid)
-
-    def run(self, test):
-        dm_type = os.environ.get('DM_TRANS', 'adb')
-        if dm_type == 'adb':
-            self.b2g_pid = get_b2g_pid(get_dm(self.marionette))
-        return super(B2GMarionetteTextTestRunner, self).run(test)
-
-
 class BaseMarionetteOptions(OptionParser):
     def __init__(self, **kwargs):
         OptionParser.__init__(self, **kwargs)
         self.parse_args_handlers = [] # Used by mixins
         self.verify_usage_handlers = [] # Used by mixins
         self.add_option('--autolog',
                         action='store_true',
                         dest='autolog',
@@ -759,19 +744,16 @@ class BaseMarionetteTestRunner(object):
         if not self.marionette:
             self.start_marionette()
             if self.emulator:
                 self.marionette.emulator.wait_for_homescreen(self.marionette)
             # Retrieve capabilities for later use
             if not self._capabilities:
                 self.capabilities
 
-        if self.capabilities['device'] != 'desktop':
-            self.textrunnerclass = B2GMarionetteTextTestRunner
-
         for test in tests:
             self.add_test(test)
 
         counter = self.repeat
         while counter >=0:
             round = self.repeat - counter
             if round > 0:
                 self.logger.info('\nREPEAT %d\n-------' % round)
--- a/testing/marionette/client/setup.py
+++ b/testing/marionette/client/setup.py
@@ -1,12 +1,12 @@
 import os
 from setuptools import setup, find_packages
 
-version = '0.7.4'
+version = '0.7.5'
 
 # get documentation from the README
 try:
     here = os.path.dirname(os.path.abspath(__file__))
     description = file(os.path.join(here, 'README.md')).read()
 except (OSError, IOError):
     description = ''