Bug 1568157 - Part 5: Move the NodePicker initialization into a getter. r=yulia
[gecko.git] / testing / marionette / mach_test_package_commands.py
blobaf2af0d8d4fa1b1a84965dd340829c08516d8018
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 from __future__ import absolute_import
7 import argparse
8 import os
9 import sys
11 from functools import partial
13 from mach.decorators import (
14 CommandProvider,
15 Command,
18 parser = None
21 def run_marionette(context, **kwargs):
22 from marionette.runtests import (
23 MarionetteTestRunner,
24 MarionetteHarness
26 from mozlog.structured import commandline
28 args = argparse.Namespace(**kwargs)
29 args.binary = args.binary or context.firefox_bin
30 args.e10s = context.mozharness_config.get('e10s', args.e10s)
32 test_root = os.path.join(context.package_root, 'marionette', 'tests')
33 if not args.tests:
34 args.tests = [os.path.join(test_root, 'testing', 'marionette', 'harness',
35 'marionette_harness', 'tests', 'unit-tests.ini')]
37 normalize = partial(context.normalize_test_path, test_root)
38 args.tests = map(normalize, args.tests)
40 commandline.add_logging_group(parser)
41 parser.verify_usage(args)
43 args.logger = commandline.setup_logging("Marionette Unit Tests",
44 args,
45 {"mach": sys.stdout})
46 status = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
47 return 1 if status else 0
50 def setup_marionette_argument_parser():
51 from marionette.runner.base import BaseMarionetteArguments
52 global parser
53 parser = BaseMarionetteArguments()
54 return parser
57 @CommandProvider
58 class MachCommands(object):
60 def __init__(self, context):
61 self.context = context
63 @Command(
64 'marionette-test', category='testing',
65 description='Run a Marionette test (Check UI or the internal JavaScript '
66 'using marionette).',
67 parser=setup_marionette_argument_parser)
68 def run_marionette_test(self, **kwargs):
69 self.context.activate_mozharness_venv()
70 return run_marionette(self.context, **kwargs)