The Nengo team at ABR is excited to announce the first release of
pytest-allclose is made available under the open source MIT license so that all Python projects can make use of it to better test their numerical code.
What is pytest-allclose?
import numpy as np def test_close(allclose): x = np.linspace(-1, 1) y = x + 0.001 assert allclose(y, x, atol=0.002) assert not allclose(y, x, atol=0.0005) assert not allclose(y, x, rtol=0.002)
allclose has a few additional features for large numerical projects. You can pass in an
xtol value to compare shifted arrays:
def test_close(allclose): x = np.linspace(-1, 1) assert allclose(x[1:], x[:-1], xtol=1) assert allclose(x[3:], x[:-3], xtol=3)
And using the
pytest_allclose.report_rmses function, you can gather a summary of how close your
allclose calls are across all tests, giving you a clue as to how code changes affect test accuracy:
$ pytest ======================= test session starts ======================= pytest_allclose/tests/test_allclose.py ............ [ 63%] pytest_allclose/tests/test_pytest.py ....... [100%] ====== relative root mean squared error for allclose checks ======= mean relative RMSE: 0.32955 +/- 0.5432 (std) ==================== 19 passed in 0.92 seconds ====================
How do I use it?
To use the fixture, first install it with
pip install pytest-allclose
then you can use it in your tests by putting
allclose in the function signature, like other pytest fixtures. We recommend you add
pytest-allclose your list of test requirements as well.
Where can I learn more?
For more details and advanced usage, see the full documentation.
Where can I get help?
If you have any questions, run into any bugs, or have suggestions for new features, please file an issue on Github.