diff --git a/changelog/3748.bugfix.rst b/changelog/3748.bugfix.rst new file mode 100644 index 000000000..1cac9cb69 --- /dev/null +++ b/changelog/3748.bugfix.rst @@ -0,0 +1 @@ +Fix infinite recursion in ``pytest.approx`` with arrays in ``numpy<1.13``. diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index 8f15ea7e7..abc4d1e17 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -257,7 +257,9 @@ class ApproxScalar(ApproxBase): the pre-specified tolerance. """ if _is_numpy_array(actual): - return all(a == self for a in actual.flat) + # Call ``__eq__()`` manually to prevent infinite-recursion with + # numpy<1.13. See #3748. + return all(self.__eq__(a) for a in actual.flat) # Short-circuit exact equality. if actual == self.expected: