Skip to content

Commit d1f93f0

Browse files
committed
Type pytest.approx
1 parent 48fcc26 commit d1f93f0

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

changelog/14373.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added type annotations for ``pytest.approx``.

src/_pytest/python_api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,12 @@ def __repr__(self) -> str:
558558
return f"{self.expected} ± {tol_str}"
559559

560560

561-
def approx(expected, rel=None, abs=None, nan_ok: bool = False) -> ApproxBase:
561+
def approx(
562+
expected: Any,
563+
rel: float | Decimal | None = None,
564+
abs: float | Decimal | None = None,
565+
nan_ok: bool = False,
566+
) -> ApproxBase:
562567
"""Assert that two numbers (or two ordered sequences of numbers) are equal to each other
563568
within some tolerance.
564569

testing/python/approx.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,8 @@ def test_decimal(self):
616616
assert a != approx(x, rel=Decimal("5e-7"), abs=0)
617617
assert approx(x, rel=Decimal("5e-6"), abs=0) == a
618618
assert approx(x, rel=Decimal("5e-7"), abs=0) != a
619+
assert approx(x, rel=0, abs=Decimal("5e-3")) == a
620+
assert approx(x, rel=0, abs=Decimal("5e-7")) != a
619621

620622
def test_fraction(self):
621623
within_1e6 = [

0 commit comments

Comments
 (0)