diff --git a/AUTHORS b/AUTHORS index f3cf1b0facb..4186bd5abf8 100644 --- a/AUTHORS +++ b/AUTHORS @@ -197,6 +197,7 @@ Guido Wesdorp Guoqiang Zhang Hamza Mobeen Harald Armin Massa +Harsh Kumar Harshna Henk-Jaap Wagenaar Holger Kohr diff --git a/changelog/14456.bugfix.rst b/changelog/14456.bugfix.rst new file mode 100644 index 00000000000..9f259c686da --- /dev/null +++ b/changelog/14456.bugfix.rst @@ -0,0 +1 @@ +Fixed ``hasattr`` call in ``_as_numpy_array`` that incorrectly used the string literal ``"obj"`` instead of the variable ``obj`` when checking for ``__array_interface__``, causing objects implementing only ``__array_interface__`` to not be recognized as numpy-like arrays by ``pytest.approx``. diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index f6d5e31a588..b94752d2eab 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -906,6 +906,6 @@ def _as_numpy_array(obj: object) -> ndarray | None: return None elif isinstance(obj, np.ndarray): return obj - elif hasattr(obj, "__array__") or hasattr("obj", "__array_interface__"): + elif hasattr(obj, "__array__") or hasattr(obj, "__array_interface__"): return np.asarray(obj) return None