Bug 1640914 [wpt PR 23771] - Python 3: port tests in resource-timing, a=testonly
[gecko.git] / testing / marionette / mach_test_package_commands.py
blob6199ad7f39a30c4f9406c090e4ec57803c575cc7
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
31 test_root = os.path.join(context.package_root, 'marionette', 'tests')
32 if not args.tests:
33 args.tests = [os.path.join(test_root, 'testing', 'marionette', 'harness',
34 'marionette_harness', 'tests', 'unit-tests.ini')]
36 normalize = partial(context.normalize_test_path, test_root)
37 args.tests = list(map(normalize, args.tests))
39 commandline.add_logging_group(parser)
40 parser.verify_usage(args)
42 args.logger = commandline.setup_logging("Marionette Unit Tests",
43 args,
44 {"mach": sys.stdout})
45 status = MarionetteHarness(MarionetteTestRunner, args=vars(args)).run()
46 return 1 if status else 0
49 def setup_marionette_argument_parser():
50 from marionette.runner.base import BaseMarionetteArguments
51 global parser
52 parser = BaseMarionetteArguments()
53 return parser
56 @CommandProvider
57 class MachCommands(object):
59 def __init__(self, context):
60 self.context = context
62 @Command(
63 'marionette-test', category='testing',
64 description='Run a Marionette test (Check UI or the internal JavaScript '
65 'using marionette).',
66 parser=setup_marionette_argument_parser)
67 def run_marionette_test(self, **kwargs):
68 self.context.activate_mozharness_venv()
69 return run_marionette(self.context, **kwargs)