diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index 10762ee7b..576f6109d 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -459,8 +459,8 @@ class ApproxScalar(ApproxBase): result: bool = abs(self.expected - actual) <= self.tolerance return result - # Ignore type because of https://github.com/python/mypy/issues/4266. - __hash__ = None # type: ignore + def __hash__(self): + return hash(self.expected) @property def tolerance(self): diff --git a/testing/python/approx.py b/testing/python/approx.py index 6acb466ff..6fff32c85 100644 --- a/testing/python/approx.py +++ b/testing/python/approx.py @@ -346,6 +346,10 @@ class TestApprox: assert 10 != approx(1, rel=1e-6, abs=1e-12) assert not (10 == approx(1, rel=1e-6, abs=1e-12)) + def test_hash(self): + assert {1} == {approx(1, rel=1e-6, abs=1e-12)} + assert {1+1e-5} != {approx(1, rel=1e-6, abs=1e-12)} + def test_exactly_equal(self): examples = [ (2.0, 2.0),