Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing run-tests.py file. #4180

Merged
merged 72 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
a38622a
Removing run-test.py file
prady0t Jun 14, 2024
b20c31d
Removing redundent files
prady0t Jun 14, 2024
2c69d61
Removing redundent files
prady0t Jun 14, 2024
f762ba1
style: pre-commit fixes
pre-commit-ci[bot] Jun 14, 2024
d4b5cff
Merge branch 'develop' into removing-runtest
prady0t Jun 14, 2024
7961707
Update test_examples.py
prady0t Jun 14, 2024
4ef0462
Update noxfile.py
prady0t Jun 14, 2024
5164a03
Removing run-test.py file
prady0t Jun 14, 2024
ce862b4
Removing redundent files
prady0t Jun 14, 2024
44085cb
Removing redundent files
prady0t Jun 14, 2024
71b7008
Removing example marker
prady0t Jun 14, 2024
b48392e
adding conftest.py file
prady0t Jun 15, 2024
b3ff477
Solved merge conflicts
prady0t Jun 15, 2024
5f3ff1d
adding back changes
prady0t Jun 15, 2024
3fa3e72
style: pre-commit fixes
pre-commit-ci[bot] Jun 15, 2024
8c6579a
Update test_examples.py
prady0t Jun 15, 2024
d854f38
style: pre-commit fixes
pre-commit-ci[bot] Jun 15, 2024
9d564ac
Removing run-test.py file
prady0t Jun 14, 2024
628c14b
Removing redundent files
prady0t Jun 14, 2024
5f1d606
Removing redundent files
prady0t Jun 14, 2024
cd598ab
style: pre-commit fixes
pre-commit-ci[bot] Jun 14, 2024
73f6816
Update test_examples.py
prady0t Jun 14, 2024
10fe805
Update noxfile.py
prady0t Jun 14, 2024
774579e
adding back changes
prady0t Jun 15, 2024
9ba46e4
removing loop for file discovery
prady0t Jun 15, 2024
fd21944
removing loop for file discovery
prady0t Jun 15, 2024
d6c4871
Adding more flags to pytest
prady0t Jun 16, 2024
13f2ec6
Solved merge conflicts
prady0t Jun 16, 2024
1a7982c
style: pre-commit fixes
pre-commit-ci[bot] Jun 16, 2024
04c0d60
Merge branch 'develop' into removing-runtest
arjxn-py Jun 17, 2024
056f574
Merge remote-tracking branch 'origin/develop' into removing-runtest
prady0t Jun 25, 2024
93c3eff
Adding markers for unit and integration tests
prady0t Jun 28, 2024
d7a5bc7
Adding markers for unit and integration tests
prady0t Jun 28, 2024
16abe39
Solved conflicts
prady0t Jun 28, 2024
a0a2a4f
style: pre-commit fixes
pre-commit-ci[bot] Jun 28, 2024
5919fa4
Added back assertDomainEqual
prady0t Jun 29, 2024
fdfa126
Resolving merge conflicts
prady0t Jun 29, 2024
d0d2575
style: pre-commit fixes
pre-commit-ci[bot] Jun 29, 2024
93b4d90
Added fixture for debug mode
prady0t Jun 29, 2024
ac683e2
Merge conflicts
prady0t Jun 29, 2024
e3d2583
style: pre-commit fixes
pre-commit-ci[bot] Jun 29, 2024
5038a81
Merge branch 'develop' into removing-runtest
prady0t Jun 29, 2024
6275977
Merge branch 'develop' into removing-runtest
prady0t Jul 2, 2024
def0223
Removed style failures
prady0t Jul 3, 2024
2a0c5e9
Removed style failures
prady0t Jul 3, 2024
0fa69af
Update conftest.py
prady0t Jul 8, 2024
f1555bf
style: pre-commit fixes
pre-commit-ci[bot] Jul 8, 2024
2dca1a2
Update conftest.py
prady0t Jul 8, 2024
f202a65
Update noxfile.py
prady0t Jul 8, 2024
58ec12f
Update pyproject.toml
prady0t Jul 8, 2024
4a8021e
Update tests/testcase.py
prady0t Jul 8, 2024
3c974a4
Update tests/test_scripts.py
prady0t Jul 8, 2024
ad182e5
Update tests/test_scripts.py
prady0t Jul 8, 2024
f8164c2
style: pre-commit fixes
pre-commit-ci[bot] Jul 8, 2024
3719eb4
using -m instead of args
prady0t Jul 10, 2024
6aaac02
removed redundent files
prady0t Jul 10, 2024
e6dd193
style: pre-commit fixes
pre-commit-ci[bot] Jul 10, 2024
40212a4
fixing style failure
prady0t Jul 10, 2024
d813c77
Merge branch 'removing-runtest' of https://github.com/prady0t/PyBaMM …
prady0t Jul 10, 2024
2fde5c6
style: pre-commit fixes
pre-commit-ci[bot] Jul 10, 2024
c9bbea5
adding documentation changes
prady0t Jul 14, 2024
7ca4f0c
Merge branch 'removing-runtest' of https://github.com/prady0t/PyBaMM …
prady0t Jul 14, 2024
a50dd9b
Update CONTRIBUTING.md
prady0t Jul 15, 2024
516a3fb
Update CONTRIBUTING.md
prady0t Jul 15, 2024
2b03f87
Merge branch 'develop' into removing-runtest
prady0t Jul 19, 2024
0cd7641
adding suggestions
prady0t Jul 19, 2024
c210da2
Merge branch 'develop' into removing-runtest
kratman Jul 19, 2024
2b4c07c
removing -s flag and getting file names in scripts log
prady0t Jul 26, 2024
312a175
Merge branch 'removing-runtest' of https://github.com/prady0t/PyBaMM …
prady0t Jul 26, 2024
20e223f
Update pyproject.toml
prady0t Jul 26, 2024
3075a77
Update CONTRIBUTING.md
prady0t Jul 26, 2024
e321ede
Merge branch 'develop' into removing-runtest
arjxn-py Jul 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ The `test_optional_dependencies` function extracts `pybamm` mandatory distributi

## Testing

All code requires testing. We use the [unittest](https://docs.python.org/3.3/library/unittest.html) package for our tests. (These tests typically just check that the code runs without error, and so, are more _debugging_ than _testing_ in a strict sense. Nevertheless, they are very useful to have!)
All code requires testing. We use the [pytest](https://docs.pytest.org/en/stable/) package for our tests. (These tests typically just check that the code runs without error, and so, are more _debugging_ than _testing_ in a strict sense. Nevertheless, they are very useful to have!)

We also use [pytest](https://docs.pytest.org/en/latest/) along with the [nbmake](https://github.com/treebeardtech/nbmake) and the [pytest-xdist](https://pypi.org/project/pytest-xdist/) plugins to test the example notebooks.
We use following plugins for various needs:

[nbmake](https://github.com/treebeardtech/nbmake&#41) : plugins to test the example notebooks.

[pytest-xdist](https://pypi.org/project/pytest-xdist/&#41) : plugins to run tests in parallel.

If you have `nox` installed, to run unit tests, type

Expand All @@ -162,14 +166,14 @@ nox -s unit
else, type

```bash
python run-tests.py --unit
pytest -m unit
```

### Writing tests

Every new feature should have its own test. To create ones, have a look at the `test` directory and see if there's a test for a similar method. Copy-pasting this is a good way to start.

Next, add some simple (and speedy!) tests of your main features. If these run without exceptions that's a good start! Next, check the output of your methods using any of these [assert methods](https://docs.python.org/3.3/library/unittest.html#assert-methods).
Next, add some simple (and speedy!) tests of your main features. If these run without exceptions that's a good start! Next, check the output of your methods using [assert statements](https://docs.pytest.org/en/7.1.x/how-to/assert.html).

### Running more tests

Expand All @@ -193,7 +197,7 @@ nox -s examples
Alternatively, you may use `pytest` directly with the `--nbmake` flag:

```bash
pytest --nbmake
pytest --nbmake docs/source/examples/
```

which runs all the notebooks in the `docs/source/examples/notebooks/` folder in parallel by default, using the `pytest-xdist` plugin.
Expand Down Expand Up @@ -245,19 +249,19 @@ This also means that, if you can't fix the bug yourself, it will be much easier
1. Run individual test scripts instead of the whole test suite:

```bash
python tests/unit/path/to/test
pytest tests/unit/path/to/test
```

You can also run an individual test from a particular script, e.g.

```bash
python tests/unit/test_quick_plot.py TestQuickPlot.test_failure
pytest tests/unit/test_plotting/test_quick_plot.py::TestQuickPlot::test_simple_ode_model
```

If you want to run several, but not all, the tests from a script, you can restrict which tests are run from a particular script by using the skipping decorator:

```python
@unittest.skip("")
@pytest.mark.skip("")
def test_bit_of_code(self):
...
```
Expand Down
46 changes: 46 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pytest
import numpy as np
import pybamm


def pytest_addoption(parser):
parser.addoption(
"--scripts",
action="store_true",
default=False,
help="execute the example scripts",
)
parser.addoption(
"--unit", action="store_true", default=False, help="run unit tests"
)
parser.addoption(
"--integration",
action="store_true",
default=False,
help="run integration tests",
)


def pytest_configure(config):
config.addinivalue_line("markers", "scripts: mark test as an example script")
config.addinivalue_line("markers", "unit: mark test as a unit test")
config.addinivalue_line("markers", "integration: mark test as an integration test")


def pytest_collection_modifyitems(items):
for item in items:
if "unit" in item.nodeid:
item.add_marker(pytest.mark.unit)
elif "integration" in item.nodeid:
item.add_marker(pytest.mark.integration)


@pytest.fixture(autouse=True)
# Set the random seed to 42 for all tests
def set_random_seed():
np.random.seed(42)


@pytest.fixture(autouse=True)
def set_debug_value():
pybamm.settings.debug_mode = True
22 changes: 15 additions & 7 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def set_iree_state():

homedir = os.getenv("HOME")
PYBAMM_ENV = {
"SUNDIALS_INST": f"{homedir}/.local",
"LD_LIBRARY_PATH": f"{homedir}/.local/lib",
"PYTHONIOENCODING": "utf-8",
"MPLBACKEND": "Agg",
# Expression evaluators (...EXPR_CASADI cannot be fully disabled at this time)
"PYBAMM_IDAKLU_EXPR_CASADI": os.getenv("PYBAMM_IDAKLU_EXPR_CASADI", "ON"),
"PYBAMM_IDAKLU_EXPR_IREE": set_iree_state(),
Expand Down Expand Up @@ -156,7 +156,7 @@ def run_integration(session):
set_environment_variables(PYBAMM_ENV, session=session)
session.install("setuptools", silent=False)
session.install("-e", ".[all,dev,jax]", silent=False)
session.run("python", "run-tests.py", "--integration")
session.run("python", "-m", "pytest", "-m", "integration")


@nox.session(name="doctests")
Expand All @@ -166,7 +166,13 @@ def run_doctests(session):
# See: https://bitbucket.org/pybtex-devs/pybtex/issues/169/
session.install("setuptools", silent=False)
session.install("-e", ".[all,dev,docs]", silent=False)
session.run("python", "run-tests.py", "--doctest")
session.run(
"python",
"-m",
"pytest",
"--doctest-plus",
"pybamm",
)


@nox.session(name="unit")
Expand All @@ -184,7 +190,7 @@ def run_unit(session):
PYBAMM_ENV.get("IREE_INDEX_URL"),
silent=False,
)
session.run("python", "run-tests.py", "--unit")
session.run("python", "-m", "pytest", "-m", "unit")


@nox.session(name="examples")
Expand All @@ -194,7 +200,9 @@ def run_examples(session):
session.install("setuptools", silent=False)
session.install("-e", ".[all,dev]", silent=False)
notebooks_to_test = session.posargs if session.posargs else []
session.run("pytest", "--nbmake", *notebooks_to_test, external=True)
session.run(
"pytest", "--nbmake", *notebooks_to_test, "docs/source/examples/", external=True
)


@nox.session(name="scripts")
Expand All @@ -206,7 +214,7 @@ def run_scripts(session):
# is fixed
session.install("setuptools", silent=False)
session.install("-e", ".[all,dev]", silent=False)
session.run("python", "run-tests.py", "--scripts")
session.run("python", "-m", "pytest", "-m", "scripts")


@nox.session(name="dev")
Expand Down Expand Up @@ -249,7 +257,7 @@ def run_tests(session):
set_environment_variables(PYBAMM_ENV, session=session)
session.install("setuptools", silent=False)
session.install("-e", ".[all,dev,jax]", silent=False)
session.run("python", "run-tests.py", "--all")
session.run("python", "-m", "pytest", "-m", "unit or integration")


@nox.session(name="docs")
Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -228,20 +228,21 @@ ignore = [
"docs/source/examples/notebooks/models/lithium-plating.ipynb" = ["F821"]

[tool.pytest.ini_options]
minversion = "6"
minversion = "8"
# Use pytest-xdist to run tests in parallel by default, exit with
# error if not installed
required_plugins = [
"pytest-xdist",
"pytest-mock",
prady0t marked this conversation as resolved.
Show resolved Hide resolved
]
addopts = [
"-nauto",
"-v",
"-ra",
"-vra",
"--strict-config",
"--strict-markers",
]
testpaths = [
"docs/source/examples/",
"tests",
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved
]
console_output_style = "progress"
xfail_strict = true
Expand Down
Loading
Loading