Skip to content

Commit dd37097

Browse files
authored
Merge pull request #8453 from encukou/rel-error-message
Fix value in error message about negative relative tolerance
2 parents 2ce446a + da4abd1 commit dd37097

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/_pytest/python_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def set_default(x, default):
319319

320320
if relative_tolerance < 0:
321321
raise ValueError(
322-
f"relative tolerance can't be negative: {absolute_tolerance}"
322+
f"relative tolerance can't be negative: {relative_tolerance}"
323323
)
324324
if math.isnan(relative_tolerance):
325325
raise ValueError("relative tolerance can't be NaN.")

testing/python/approx.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ def test_negative_tolerance(
141141
with pytest.raises(ValueError):
142142
1.1 == approx(1, rel, abs)
143143

144+
def test_negative_tolerance_message(self):
145+
# Error message for negative tolerance should include the value.
146+
with pytest.raises(ValueError, match="-3"):
147+
0 == approx(1, abs=-3)
148+
with pytest.raises(ValueError, match="-3"):
149+
0 == approx(1, rel=-3)
150+
144151
def test_inf_tolerance(self):
145152
# Everything should be equal if the tolerance is infinite.
146153
large_diffs = [(1, 1000), (1e-50, 1e50), (-1.0, -1e300), (0.0, 10)]

0 commit comments

Comments
 (0)