Skip to content

Commit

Permalink
Enhance nox
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-kirienko committed Jan 22, 2024
1 parent 7edab65 commit 6c5092e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6c5092e

Please sign in to comment.