Bug 1433941 - Passed remainder arguments as it is |mach python-test| r=ahal

Differential Revision: https://phabricator.services.mozilla.com/D47832

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Anmol Agarwal 2019-10-04 18:32:37 +00:00
Родитель 5b875f2afd
Коммит d2dbcf8eba
3 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -286,7 +286,7 @@ class CommandArgument(object):
# These are the assertions we make in dispatcher.py about
# those types of CommandArguments.
assert len(args) == 1
assert all(k in ('default', 'nargs', 'help', 'group') for k in kwargs)
assert all(k in ('default', 'nargs', 'help', 'group', 'metavar') for k in kwargs)
self._command_args = (args, kwargs)
def __call__(self, func):

Просмотреть файл

@ -200,7 +200,7 @@ class CommandAction(argparse.Action):
# pick any extra argument, wherever they are.
# Assume a limited CommandArgument for those arguments.
assert len(arg[0]) == 1
assert all(k in ('default', 'nargs', 'help') for k in arg[1])
assert all(k in ('default', 'nargs', 'help', 'metavar') for k in arg[1])
remainder = arg
else:
subparser.add_argument(*arg[0], **arg[1])

Просмотреть файл

@ -97,6 +97,10 @@ class MachCommands(MachCommandBase):
metavar='TEST',
help=('Tests to run. Each test can be a single file or a directory. '
'Default test resolution relies on PYTHON_UNITTEST_MANIFESTS.'))
@CommandArgument('extra', nargs=argparse.REMAINDER,
metavar='PYTEST ARGS',
help=('Arguments that aren\'t recognized by mach. These will be '
'passed as it is to pytest'))
def python_test(self, *args, **kwargs):
try:
tempdir = os.environ[b'PYTHON_TEST_TMP'] = str(tempfile.mkdtemp(suffix='-python-test'))
@ -113,6 +117,7 @@ class MachCommands(MachCommandBase):
jobs=None,
python=None,
exitfirst=False,
extra=None,
**kwargs):
python = python or self.virtualenv_manager.python_path
self.activate_pipenv(pipfile=None, populate=True, python=python)
@ -154,6 +159,9 @@ class MachCommands(MachCommandBase):
sequential = []
os.environ.setdefault('PYTEST_ADDOPTS', '')
if extra:
os.environ['PYTEST_ADDOPTS'] += " " + " ".join(extra)
if exitfirst:
sequential = tests
os.environ['PYTEST_ADDOPTS'] += " -x"