From bf418b34ff30069a84a6f3be928066e3b1eccb74 Mon Sep 17 00:00:00 2001 From: Natalia Mokeeva <91160475+natmokval@users.noreply.github.com> Date: Fri, 4 Apr 2025 16:53:37 +0200 Subject: [PATCH] Doc: clarify `approx` behavior regarding int and bools (#13341) Fixes #13218 (cherry picked from commit 6964cf105e6256682271e5bc1ad32c08a58df4bc) --- changelog/13218.doc.rst | 1 + src/_pytest/python_api.py | 9 +++++++++ 2 files changed, 10 insertions(+) create mode 100644 changelog/13218.doc.rst diff --git a/changelog/13218.doc.rst b/changelog/13218.doc.rst new file mode 100644 index 00000000000..907a817e895 --- /dev/null +++ b/changelog/13218.doc.rst @@ -0,0 +1 @@ +Pointed out in the :func:`pytest.approx` documentation that it considers booleans unequal to numeric zero or one. diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index 4e8271507fb..f58baf39fc0 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -697,6 +697,15 @@ def approx(expected, rel=None, abs=None, nan_ok: bool = False) -> ApproxBase: from the `re_assert package `_. + + .. note:: + + Unlike built-in equality, this function considers + booleans unequal to numeric zero or one. For example:: + + >>> 1 == approx(True) + False + .. warning:: .. versionchanged:: 3.2