From 6c5092ef6cc6b17f89b0b9e0d10a824da3347f03 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Mon, 22 Jan 2024 19:56:09 +0200 Subject: [PATCH] Enhance nox --- CONTRIBUTING.md | 8 ++++++++ noxfile.py | 14 +++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 89f60df..51a489b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,6 +37,14 @@ If you want to start from scratch, use `clean`: nox -s clean ``` +Positional arguments given to Nox are passed over to PyTest as-is, +which can be used to run tests selectively or bail at the first failure: + +```bash +nox -s test -- -x yakut/param/formatter.py -k test_format_param +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PyTest options +``` + #### Running tests/linters selectively from a virtual environment created by Nox Running the full test suite using Nox takes too much time for interactive testing during development. diff --git a/noxfile.py b/noxfile.py index 065b658..72fedad 100644 --- a/noxfile.py +++ b/noxfile.py @@ -70,20 +70,20 @@ def test(session): # We do it here because the sudo may ask the user for the password; doing that from the suite is inconvenient. session.run("sudo", "setcap", "cap_net_raw+eip", str(Path(session.bin, "python").resolve()), external=True) - # The directories to test may be overridden if needed when invoking Nox. - src_dirs = [(ROOT_DIR / t) for t in (session.posargs or ["yakut", "tests"])] + src_dirs = [(ROOT_DIR / t) for t in ["yakut", "tests"]] # Run PyTest and make a code coverage report. - env = { - "PYTHONPATH": str(DEPS_DIR), - "PATH": os.pathsep.join([session.env["PATH"], str(DEPS_DIR)]), - } + # Positional arguments passed to Nox after "--" are forwarded to PyTest as-is. session.run( "pytest", *map(str, src_dirs), # Log format cannot be specified in setup.cfg https://github.com/pytest-dev/pytest/issues/3062 r"--log-file-format=%(asctime)s %(levelname)-3.3s %(name)s: %(message)s", - env=env, + *session.posargs, + env={ + "PYTHONPATH": str(DEPS_DIR), + "PATH": os.pathsep.join([session.env["PATH"], str(DEPS_DIR)]), + }, ) # The coverage threshold is intentionally set low for interactive runs because when running locally