From 7d13599ba1ad61d4423bc60db14c46a742f1e3fe Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 1 Aug 2018 08:04:09 -0300 Subject: [PATCH 1/2] Fix recursion in pytest.approx() with arrays in numpy<1.13 --- changelog/3748.bugfix.rst | 1 + src/_pytest/python_api.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelog/3748.bugfix.rst diff --git a/changelog/3748.bugfix.rst b/changelog/3748.bugfix.rst new file mode 100644 index 00000000000..1cac9cb6995 --- /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 5331d8a84a3..411562eb82a 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -211,7 +211,7 @@ def __eq__(self, actual): the pre-specified tolerance. """ if _is_numpy_array(actual): - return all(a == self for a in actual.flat) + return all(self == a for a in actual.flat) # Short-circuit exact equality. if actual == self.expected: From b8255308d65d91a464991259b0b233dcc4969486 Mon Sep 17 00:00:00 2001 From: Kale Kundert Date: Wed, 1 Aug 2018 12:08:03 -0700 Subject: [PATCH 2/2] Make the infinite-recusrion fix more explicit. So we remember what happened and don't accidentally regress in the future. --- src/_pytest/python_api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index 411562eb82a..596bac19165 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -211,7 +211,9 @@ def __eq__(self, actual): the pre-specified tolerance. """ if _is_numpy_array(actual): - return all(self == a 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: