diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index f35351e2a..04022b9fe 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -211,10 +211,9 @@ class ApproxScalar(ApproxBase): the pre-specified tolerance. """ if _is_numpy_array(actual): - return ( - ApproxNumpy(actual, rel=self.rel, abs=self.abs, nan_ok=self.nan_ok) - == self.expected - ) + import numpy as np + + return np.all(abs(self.expected - actual) <= self.tolerance) # Short-circuit exact equality. if actual == self.expected: diff --git a/testing/python/approx.py b/testing/python/approx.py index b93ff241b..09487cc73 100644 --- a/testing/python/approx.py +++ b/testing/python/approx.py @@ -346,15 +346,22 @@ class TestApprox(object): """ quick check that numpy rel/abs args are handled correctly for comparison against an np.array + - 3.6.4 would approx both actual / expected if np.array + regardless of which value was passed to approx() + Means tolerance could be calculated against bad test return """ np = pytest.importorskip("numpy") expected = 100 actual = 99 assert actual != pytest.approx(expected, abs=0.1, rel=0) assert np.array(actual) != pytest.approx(expected, abs=0.1, rel=0) + assert actual != pytest.approx(np.array(expected), abs=0.1, rel=0) + assert np.array(actual) != pytest.approx(np.array(expected), abs=0.1, rel=0) assert actual == pytest.approx(expected, abs=0, rel=0.01) - assert np.array(actual) == pytest.approx(expected, abs=0, rel=0.1) + assert np.array(actual) == pytest.approx(expected, abs=0, rel=0.01) + assert actual == pytest.approx(np.array(expected), abs=0, rel=0.01) + assert np.array(actual) == pytest.approx(np.array(expected), abs=0, rel=0.01) def test_numpy_array_wrong_shape(self): np = pytest.importorskip("numpy")