diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 274ba954e..f237f5221 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -162,16 +162,24 @@ If you have nox installed, to run unit tests, type nox -s unit ``` -Alternatively, to run tests standalone with pytest, run, +For individual tests, use: + +```bash +nox -s tests -- tests/unit/test_costs.py::TestCosts::test_costs +``` + +which will run the specified test, alternatively you can run all tests within a file by removing the trailing `::test_costs` in the above command. + +Alternatively, to run tests standalone with pytest, use: ```bash pytest --unit -v ``` -To run individual test files, you can use +To run individual test files with nox, you can use ```bash -pytest tests/unit/path/to/test --unit -v +pytest tests/unit/path/to/test.py --unit -v ``` And for individual tests, diff --git a/noxfile.py b/noxfile.py index 2032476f2..4b4b34779 100644 --- a/noxfile.py +++ b/noxfile.py @@ -97,12 +97,20 @@ def notebooks_overwrite(session): @nox.session(name="tests") def run_tests(session): - """Run all the tests.""" + """Run all or a user-defined set of tests.""" session.install("-e", ".[all,dev]", silent=False) if PYBOP_SCHEDULED: session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False) + specific_tests = session.posargs if session.posargs else [] session.run( - "pytest", "--unit", "--integration", "--nbmake", "--examples", "-n", "auto" + "pytest", + "--unit", + "--integration", + "--nbmake", + "--examples", + "-n", + "auto", + *specific_tests, )