Files
tubestation/testing/mochitest/mach_test_package_commands.py
Andrew Halberstadt 712da3ba96 Bug 1300163 - Lazy load certain mach context attributes using the 'key' mechanism, r=armenzg
You can set attributes on a mach context by using the 'key' argument to the context_handler. Basically,
whatever gets returned by the handler when <key> is passed in, will get set (i.e cached) on the context
object for fast retrieval next time. This is a way to lazy load these attributes.

Previously I was setting functions like 'find_firefox()' on the context object, and then having the
mach_commands call that directly. But this way is much cleaner.

Now, the loaded 'mozharness_config' can be stored as an attribute on the context. Also 'find_firefox()'
is now an attribute called 'firefox_bin'.

MozReview-Commit-ID: 4lsKGpizfH7
2016-09-02 14:35:14 -04:00

58 lines
1.6 KiB
Python

# 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
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
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)
return run_mochitest_desktop(context, args)
def run_mochitest_desktop(context, args):
args.app = args.app or context.firefox_bin
args.utilityPath = context.bin_dir
args.extraProfileFiles.append(os.path.join(context.bin_dir, 'plugins'))
from runtests import run_test_harness
return run_test_harness(parser, args)
def setup_argument_parser():
from mochitest_options import MochitestArgumentParser
global parser
parser = MochitestArgumentParser(app='generic')
return parser
@CommandProvider
class MochitestCommands(object):
def __init__(self, context):
self.context = context
@Command('mochitest', category='testing',
description='Run the mochitest harness.',
parser=setup_argument_parser)
def mochitest(self, **kwargs):
return run_mochitest(self.context, **kwargs)