run_pytest: switch to chromite commandline parser
We used argparse & parse_known_args to pass flags down to pytest.
We can already accomplish this with the chromite parser by using
-- to delimit chromite & pytest options (when they conflict).
Using our standard parser takes care of setting up the logging
module which avoids running everything at debug by default.
BUG=None
TEST=`./run_pytest` works
TEST=`./run_pytest -- help` shows pytest options
Change-Id: I1bd4b98b2e879ffab042ad98802a19a41f17eb1f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2532053
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Chris McDonald <cjmcdonald@chromium.org>
diff --git a/scripts/run_pytest.py b/scripts/run_pytest.py
index 707f069..53fdda7 100644
--- a/scripts/run_pytest.py
+++ b/scripts/run_pytest.py
@@ -7,13 +7,13 @@
from __future__ import print_function
-import argparse
import os
import sys
import pytest # pylint: disable=import-error
from chromite.lib import cgroups
+from chromite.lib import commandline
from chromite.lib import constants
from chromite.lib import cros_build_lib
from chromite.lib import gs
@@ -23,7 +23,10 @@
def main(argv):
parser = get_parser()
- opts, pytest_args = parser.parse_known_args()
+ opts = parser.parse_args()
+
+ pytest_args = opts.pytest_args
+
if opts.quick:
if not cros_build_lib.IsInsideChroot() and opts.chroot:
logging.warning('Tests start up faster when run from inside the chroot.')
@@ -98,10 +101,9 @@
def get_parser():
"""Build the parser for command line arguments."""
- parser = argparse.ArgumentParser(
+ parser = commandline.ArgumentParser(
description=__doc__,
- epilog='To see the help output for pytest, run `pytest --help` inside '
- 'the chroot.',
+ epilog='To see the help output for pytest:\n$ %(prog)s -- --help',
)
parser.add_argument(
'--quickstart',
@@ -117,4 +119,10 @@
help="Don't initialize or enter a chroot for the test invocation. May "
'cause tests to unexpectedly fail!',
)
+ parser.add_argument(
+ 'pytest_args',
+ metavar='pytest arguments',
+ nargs='*',
+ help='Arguments to pass down to pytest (use -- to help separate)',
+ )
return parser