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

Final pytest migration #4443

Merged
merged 11 commits into from
Sep 28, 2024
2 changes: 1 addition & 1 deletion docs/source/user_guide/installation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ Dependency
`pre-commit <https://pre-commit.com/index.html>`__ \- dev For managing and maintaining multi-language pre-commit hooks.
`ruff <https://beta.ruff.rs/docs/>`__ \- dev For code formatting.
`nox <https://nox.thea.codes/en/stable/>`__ \- dev For running testing sessions in multiple environments.
`pytest-subtests <https://github.com/pytest-dev/pytest-subtests/>`__ \- dev For subtests pytest fixture.
`pytest-cov <https://pytest-cov.readthedocs.io/en/stable/>`__ \- dev For calculating test coverage.
`parameterized <https://github.com/wolever/parameterized>`__ \- dev For test parameterization.
`pytest <https://docs.pytest.org/en/stable/>`__ 6.0.0 dev For running the test suites.
`pytest-doctestplus <https://github.com/scientific-python/pytest-doctestplus>`__ \- dev For running doctests.
`pytest-xdist <https://pytest-xdist.readthedocs.io/en/latest/>`__ \- dev For running tests in parallel across distributed workers.
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,11 @@ dev = [
"pytest-cov",
# For doctest
"pytest-doctestplus",
# For test parameterization
"parameterized>=0.9",
# pytest and its plugins
"pytest>=6",
"pytest-xdist",
"pytest-mock",
"pytest-subtests",
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved
# For testing Jupyter notebooks
"nbmake",
# To access the metadata for python packages
Expand Down Expand Up @@ -230,6 +229,7 @@ minversion = "8"
required_plugins = [
"pytest-xdist",
"pytest-mock",
"pytest-subtests",
]
norecursedirs = 'pybind11*'
addopts = [
Expand Down
168 changes: 77 additions & 91 deletions tests/unit/test_experiments/test_simulation_with_experiment.py

Large diffs are not rendered by default.

654 changes: 320 additions & 334 deletions tests/unit/test_expression_tree/test_binary_operators.py

Large diffs are not rendered by default.

Large diffs are not rendered by default.

18 changes: 4 additions & 14 deletions tests/unit/test_parameters/test_parameter_sets/test_OKane2022.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# Tests for O'Kane (2022) parameter set
#

import pytest
import pybamm
import unittest


class TestOKane2022(unittest.TestCase):
class TestOKane2022:
def test_functions(self):
param = pybamm.ParameterValues("OKane2022")
sto = pybamm.Scalar(0.9)
Expand Down Expand Up @@ -40,16 +40,6 @@ def test_functions(self):
}

for name, value in fun_test.items():
self.assertAlmostEqual(
param.evaluate(param[name](*value[0])), value[1], places=4
assert param.evaluate(param[name](*value[0])) == pytest.approx(
value[1], abs=0.0001
)


if __name__ == "__main__":
print("Add -v for more debug output")
import sys

if "-v" in sys.argv:
debug = True
pybamm.settings.debug_mode = True
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
#

import pybamm
import unittest


class TestParameterValuesWithModel(unittest.TestCase):
def test_parameter_values_with_model(self):
class TestParameterValuesWithModel:
def test_parameter_values_with_model(self, subtests):
param_to_model = {
"Ai2020": pybamm.lithium_ion.DFN(
{"particle mechanics": "swelling and cracking"}
Expand Down Expand Up @@ -46,16 +45,6 @@ def test_parameter_values_with_model(self):

# Loop over each parameter set, testing that parameters can be set
for param, model in param_to_model.items():
with self.subTest(param=param):
with subtests.test(param=param):
parameter_values = pybamm.ParameterValues(param)
parameter_values.process_model(model)


if __name__ == "__main__":
print("Add -v for more debug output")
import sys

if "-v" in sys.argv:
debug = True
pybamm.settings.debug_mode = True
unittest.main()
Loading
Loading