From 531122efc07c0c68a0c1d63e20f5f927d895d807 Mon Sep 17 00:00:00 2001 From: Brady Planden Date: Fri, 27 Sep 2024 17:08:42 +0100 Subject: [PATCH 1/2] tests: adds positional args to nox session for user-definable test selection --- CONTRIBUTING.md | 12 ++++++++++-- noxfile.py | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 274ba954e..5c890fd5d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -162,13 +162,21 @@ 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 cost, 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 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, ) From ba1392cdb86192f0a9a04676f854d94b746592c9 Mon Sep 17 00:00:00 2001 From: Brady Planden <55357039+BradyPlanden@users.noreply.github.com> Date: Sat, 28 Sep 2024 11:34:32 +0100 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5c890fd5d..f237f5221 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -168,7 +168,7 @@ For individual tests, use: nox -s tests -- tests/unit/test_costs.py::TestCosts::test_costs ``` -which will run the specified cost, alternatively you can run all tests within a file by removing the trailing `::test_costs` in the above command. +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: @@ -179,7 +179,7 @@ pytest --unit -v 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,