diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index dd519154a..67c05d101 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -444,10 +444,10 @@ class ApproxScalar(ApproxBase): # NB: we need Complex, rather than just Number, to ensure that __abs__, # __sub__, and __float__ are defined. Also, consider bool to be # nonnumeric, even though it has the required arithmetic. - if not ( + if isinstance(self.expected, bool) or not ( isinstance(self.expected, (Complex, Decimal)) and isinstance(actual, (Complex, Decimal)) - ) or isinstance(self.expected, bool): + ): return False # Allow the user to control whether NaNs are considered equal to each diff --git a/testing/python/approx.py b/testing/python/approx.py index 2b83e8e97..65071b4b5 100644 --- a/testing/python/approx.py +++ b/testing/python/approx.py @@ -559,11 +559,11 @@ class TestApprox: assert approx(x, rel=5e-6, abs=0) == a assert approx(x, rel=5e-7, abs=0) != a - def test_bool(self): - assert True == approx(True) - assert False == approx(False) - assert True != approx(False) - assert True != approx(False, abs=2) + def test_expecting_bool(self): + assert True == approx(True) # noqa: E712 + assert False == approx(False) # noqa: E712 + assert True != approx(False) # noqa: E712 + assert True != approx(False, abs=2) # noqa: E712 assert 1 != approx(True) def test_list(self):