From 1f131afb078e714521ed4e400ad7bfeb5836dd14 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 16 Mar 2021 18:54:52 +0100 Subject: [PATCH 1/3] Fix value in error message about negative relative tolerance --- src/_pytest/python_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index 7e0c86479..8158afd45 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -317,7 +317,7 @@ class ApproxScalar(ApproxBase): if relative_tolerance < 0: raise ValueError( - f"relative tolerance can't be negative: {absolute_tolerance}" + f"relative tolerance can't be negative: {relative_tolerance}" ) if math.isnan(relative_tolerance): raise ValueError("relative tolerance can't be NaN.") From 43b451e95e978f0828b293421c9d0930b7e0db1e Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 16 Mar 2021 20:09:17 +0100 Subject: [PATCH 2/3] Add tests for the error message --- testing/python/approx.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/testing/python/approx.py b/testing/python/approx.py index db6124e39..a8b2955d7 100644 --- a/testing/python/approx.py +++ b/testing/python/approx.py @@ -141,6 +141,13 @@ class TestApprox: with pytest.raises(ValueError): 1.1 == approx(1, rel, abs) + def test_negative_tolerance_message(self): + # Error message for negative tolerance should include the value. + with pytest.raises(ValueError, match='-3'): + 0 == approx(1, abs=-3) + with pytest.raises(ValueError, match='-3'): + 0 == approx(1, rel=-3) + def test_inf_tolerance(self): # Everything should be equal if the tolerance is infinite. large_diffs = [(1, 1000), (1e-50, 1e50), (-1.0, -1e300), (0.0, 10)] From da4abd1c8273b39b5bc7d22c1e99e05d3300a9ba Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 16 Mar 2021 19:10:50 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- testing/python/approx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/python/approx.py b/testing/python/approx.py index a8b2955d7..538dbd397 100644 --- a/testing/python/approx.py +++ b/testing/python/approx.py @@ -143,9 +143,9 @@ class TestApprox: def test_negative_tolerance_message(self): # Error message for negative tolerance should include the value. - with pytest.raises(ValueError, match='-3'): + with pytest.raises(ValueError, match="-3"): 0 == approx(1, abs=-3) - with pytest.raises(ValueError, match='-3'): + with pytest.raises(ValueError, match="-3"): 0 == approx(1, rel=-3) def test_inf_tolerance(self):