When using pytest.approx to compare lists in a test, a ModuleNotFoundError is raised for Numpy whenever the test fails. If the test succeeds, there is no such error.
It appears that pytest.approx does not require Numpy to run, but the error message requires Numpy to display the details. Since pytest.approx does not require Numpy to function correctly, it should not require Numpy to display the error.
============================= test session starts ==============================
platform darwin -- Python 3.9.0, pytest-7.0.1, pluggy-1.0.0
collected 1 item
test_approx.py F [100%]
=================================== FAILURES ===================================
_________________________________ test_approx __________________________________
> assert [1, 2] == pytest.approx([1.001, 2.002])
E AssertionError: assert [1, 2] == approx([1.001...02 ± 2.0e-06])
E (pytest_assertion plugin: representation of details failed: /Users/adalessa/Downloads/diffusion-master 2/venv/lib/python3.9/site-packages/_pytest/python_api.py:323: ModuleNotFoundError: No module named 'numpy'.
E Probably an object has a faulty __repr__.)
=========================== short test summary info ============================
FAILED test_approx.py::test_approx - AssertionError: assert [1, 2] == approx(...
============================== 1 failed in 0.04s ===============================
No ModuleNotFoundError: No module named 'numpy'. which makes the whole error message confusing and leads you to believe it failed because Numpy is not installed instead of the fact it was an assertion error.
The text was updated successfully, but these errors were encountered:
np.inf should be replaced by math.inf, and the numpy import at the beginning of the function should be removed. Also we should fix our test suite: TestApprox.test_error_messages currently tests scalars, lists and numpy arrays, but it uses importorskip at the beginning, so we skip the tests if numpy is not installed. We should split the test into two: one which tests everything not-numpy related, and one which tests numpy-data and depends on numpy.
Since there has been no activity from @dzht19 on this issue, I decided to open a quick PR. I will be glad if you take a look at it. Btw, this would be my first contribution ever and I hope you point out if I have been sloppy somewhere :)