Backed out changeset 6dcb52d270c7 (bug 1288827) for breaking mochitests
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Thu, 28 Jul 2016 17:04:42 +0200
changeset 332104 d6a7c3753a062a6c316bff09133f066981c3be99
parent 332103 6dcb52d270c7c008563b1f739a4fa2e2db31a531
child 332105 b121d125e6a56d29d742049580faee49104665a6
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1288827
milestone50.0a1
backs out6dcb52d270c7c008563b1f739a4fa2e2db31a531
Backed out changeset 6dcb52d270c7 (bug 1288827) for breaking mochitests
testing/mochitest/mach_commands.py
testing/mochitest/mach_test_package_commands.py
testing/mochitest/mochitest_options.py
testing/mochitest/runtests.py
--- a/testing/mochitest/mach_commands.py
+++ b/testing/mochitest/mach_commands.py
@@ -126,18 +126,16 @@ ALL_FLAVORS = {
         }
     },
 }
 
 SUPPORTED_APPS = ['firefox', 'b2g', 'android', 'mulet']
 SUPPORTED_FLAVORS = list(chain.from_iterable([f['aliases'] for f in ALL_FLAVORS.values()]))
 CANONICAL_FLAVORS = sorted([f['aliases'][0] for f in ALL_FLAVORS.values()])
 
-parser = None
-
 
 class MochitestRunner(MozbuildObject):
 
     """Easily run mochitests.
 
     This currently contains just the basics for running mochitests. We may want
     to hook up result parsing, etc.
     """
@@ -194,17 +192,17 @@ class MochitestRunner(MozbuildObject):
         options = Namespace(**kwargs)
 
         from manifestparser import TestManifest
         if tests:
             manifest = TestManifest()
             manifest.tests.extend(tests)
             options.manifestFile = manifest
 
-        return mochitest.run_test_harness(parser, options)
+        return mochitest.run_test_harness(options)
 
     def run_desktop_test(self, context, tests=None, suite=None, **kwargs):
         """Runs a mochitest.
 
         suite is the type of mochitest to run. It can be one of ('plain',
         'chrome', 'browser', 'a11y', 'jetpack-package', 'jetpack-addon').
         """
         # runtests.py is ambiguous, so we load the file/module manually.
@@ -239,17 +237,17 @@ class MochitestRunner(MozbuildObject):
             # refresh the page to pick up modifications. Therefore leave the browser
             # open if only running a single mochitest-plain test. This behaviour can
             # be overridden by passing in --keep-open=false.
             if len(tests) == 1 and options.keep_open is None and suite == 'plain':
                 options.keep_open = True
 
         # We need this to enable colorization of output.
         self.log_manager.enable_unstructured()
-        result = mochitest.run_test_harness(parser, options)
+        result = mochitest.run_test_harness(options)
         self.log_manager.disable_unstructured()
         return result
 
     def run_android_test(self, context, tests, suite=None, **kwargs):
         host_ret = verify_host_bin()
         if host_ret != 0:
             return host_ret
 
@@ -263,17 +261,17 @@ class MochitestRunner(MozbuildObject):
         options = Namespace(**kwargs)
 
         from manifestparser import TestManifest
         if tests:
             manifest = TestManifest()
             manifest.tests.extend(tests)
             options.manifestFile = manifest
 
-        return runtestsremote.run_test_harness(parser, options)
+        return runtestsremote.run_test_harness(options)
 
     def run_robocop_test(self, context, tests, suite=None, **kwargs):
         host_ret = verify_host_bin()
         if host_ret != 0:
             return host_ret
 
         import imp
         path = os.path.join(self.mochitest_dir, 'runrobocop.py')
@@ -285,17 +283,17 @@ class MochitestRunner(MozbuildObject):
         options = Namespace(**kwargs)
 
         from manifestparser import TestManifest
         if tests:
             manifest = TestManifest()
             manifest.tests.extend(tests)
             options.manifestFile = manifest
 
-        return runrobocop.run_test_harness(parser, options)
+        return runrobocop.run_test_harness(options)
 
 # parser
 
 
 def setup_argument_parser():
     build_obj = MozbuildObject.from_environment(cwd=here)
 
     build_path = os.path.join(build_obj.topobjdir, 'build')
@@ -318,19 +316,17 @@ def setup_argument_parser():
     if conditions.is_android(build_obj):
         # On Android, check for a connected device (and offer to start an
         # emulator if appropriate) before running tests. This check must
         # be done in this admittedly awkward place because
         # MochitestArgumentParser initialization fails if no device is found.
         from mozrunner.devices.android_device import verify_android_device
         verify_android_device(build_obj, install=True, xre=True)
 
-    global parser
-    parser = MochitestArgumentParser()
-    return parser
+    return MochitestArgumentParser()
 
 
 # condition filters
 
 def is_buildapp_in(*apps):
     def is_buildapp_supported(cls):
         for a in apps:
             c = getattr(conditions, 'is_{}'.format(a), None)
--- a/testing/mochitest/mach_test_package_commands.py
+++ b/testing/mochitest/mach_test_package_commands.py
@@ -1,49 +1,36 @@
 # 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 unicode_literals
 
+from argparse import Namespace
 import os
-from argparse import Namespace
-from functools import partial
 
 from mach.decorators import (
     CommandProvider,
     Command,
 )
 
-parser = None
-
 
 def run_mochitest(context, **kwargs):
     args = Namespace(**kwargs)
     args.certPath = context.certs_dir
     args.utilityPath = context.bin_dir
     args.extraProfileFiles.append(os.path.join(context.bin_dir, 'plugins'))
 
-    if not args.app:
-        args.app = context.find_firefox()
-
-    if args.test_paths:
-        test_root = os.path.join(context.package_root, 'mochitest', 'tests')
-        normalize = partial(context.normalize_test_path, test_root)
-        args.test_paths = map(normalize, args.test_paths)
-
     from runtests import run_test_harness
-    return run_test_harness(parser, args)
+    return run_test_harness(args)
 
 
 def setup_argument_parser():
     from mochitest_options import MochitestArgumentParser
-    global parser
-    parser = MochitestArgumentParser(app='generic')
-    return parser
+    return MochitestArgumentParser(app='generic')
 
 
 @CommandProvider
 class MochitestCommands(object):
 
     def __init__(self, context):
         self.context = context
 
--- a/testing/mochitest/mochitest_options.py
+++ b/testing/mochitest/mochitest_options.py
@@ -1246,8 +1246,15 @@ class MochitestArgumentParser(ArgumentPa
         containers = container_map[self.app]
         self._containers = [c() for c in containers]
         return self._containers
 
     def validate(self, args):
         for container in self.containers:
             args = container.validate(self, args, self.context)
         return args
+
+    def parse_args(self, *args, **kwargs):
+        return self.validate(ArgumentParser.parse_args(self, *args, **kwargs))
+
+    def parse_known_args(self, *args, **kwargs):
+        args, remainder = ArgumentParser.parse_known_args(self, *args, **kwargs)
+        return (self.validate(args), remainder)
--- a/testing/mochitest/runtests.py
+++ b/testing/mochitest/runtests.py
@@ -46,21 +46,20 @@ from manifestparser.filters import (
     pathprefix,
     subsuite,
     tags,
 )
 
 try:
     from marionette import Marionette
     from marionette_driver.addons import Addons
-except ImportError, e:
-    # Defer ImportError until attempt to use Marionette
-    def reraise(*args, **kwargs):
-        raise(e)
-    Marionette = reraise
+
+except ImportError:
+    # Marionette not needed nor supported on android
+    Marionette = None
 
 from leaks import ShutdownLeaks, LSANLeaks
 from mochitest_options import (
     MochitestArgumentParser, build_obj, get_default_valgrind_suppression_files
 )
 from mozprofile import Profile, Preferences
 from mozprofile.permissions import ServerLocations
 from urllib import quote_plus as encodeURIComponent
@@ -2661,19 +2660,17 @@ class MochitestDesktop(MochitestBase):
 
             rootdir = '/'.join(test['path'].split('/')[:-1])
             if rootdir not in dirlist:
                 dirlist.append(rootdir)
 
         return dirlist
 
 
-def run_test_harness(parser, options):
-    parser.validate(options)
-
+def run_test_harness(options):
     logger_options = {
         key: value for key, value in vars(options).iteritems()
         if key.startswith('log') or key == 'valgrind'}
 
     runner = MochitestDesktop(logger_options)
 
     options.runByDir = False
 
@@ -2715,12 +2712,12 @@ def run_test_harness(parser, options):
 def cli(args=sys.argv[1:]):
     # parse command line options
     parser = MochitestArgumentParser(app='generic')
     options = parser.parse_args(args)
     if options is None:
         # parsing error
         sys.exit(1)
 
-    return run_test_harness(parser, options)
+    return run_test_harness(options)
 
 if __name__ == "__main__":
     sys.exit(cli())