From dfa90bba2de684c9481a6d177eecbf4ccb33d37d Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 25 Apr 2024 07:58:05 -0300 Subject: [PATCH] Apply suggestions from code review --- changelog/12114.bugfix.rst | 2 +- src/_pytest/python_api.py | 2 +- testing/python/approx.py | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/changelog/12114.bugfix.rst b/changelog/12114.bugfix.rst index 798496925..220832da5 100644 --- a/changelog/12114.bugfix.rst +++ b/changelog/12114.bugfix.rst @@ -1 +1 @@ -Fixed attribute error in pytest.approx for types implicitly convertible to numpy arrays by converting other_side to a numpy array so that np_array_shape != other_side.shape can be properly checked. +Fixed error in :func:`pytest.approx` when used with `numpy` arrays and comparing with other types. diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index a4ab80e2b..f6986a6a4 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -163,7 +163,7 @@ class ApproxNumpy(ApproxBase): self._approx_scalar, self.expected.tolist() ) - # convert other_side to numpy array to ensure shape attribute is available + # Convert other_side to numpy array to ensure shape attribute is available. other_side_as_array = _as_numpy_array(other_side) assert other_side_as_array is not None diff --git a/testing/python/approx.py b/testing/python/approx.py index 968e88285..cf8cc8d03 100644 --- a/testing/python/approx.py +++ b/testing/python/approx.py @@ -763,7 +763,8 @@ class TestApprox: assert a12 != approx(a21) assert a21 != approx(a12) - def test_numpy_array_implicit_conversion(self): + def test_numpy_array_implicit_conversion(self) -> None: + """#12114.""" np = pytest.importorskip("numpy") class ImplicitArray: