You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TEST: handle pytest 8.3.4 change in bool tests with approx
Fixsherpa#2202
In pytest 8.3.3 and earlier
>>> import numpy as np; import pytest
>>> pytest.__version__
'8.3.3'
>>> np.ones(2, dtype=bool) == pytest.approx([True, True])
True
However, pytest 8.3.4 now causes this to fail
>>> import numpy as np; import pytest
>>> pytest.__version__
'8.3.4'
>>> np.ones(2, dtype=bool) == pytest.approx([True, True])
False
This is because of "pytest.approx considers boolean numeric types"
pytest-dev/pytest#9353
The solution is to make the "expected" value be a ndarray, and so
>>> np.ones(2, dtype=bool) == pytest.approx(np.asarray([True, True]))
True
holds with both pytest 8.3.3 and 8.3.4.
So this commit basically goes through and updates the tests so that
we use a ndarray for boolean arrays.
An alternative would be to change from
assert got == pytest.approx(expected)
to something like
assert np.all(got == expected)
However, the error message when the array lengths are different or
an element is different are a **lot less** useful, and the change would
be even-more invasive than this change.
0 commit comments