From 76e108d06cf9f3e7ee2927dd85d7c3c56877f603 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 8 Dec 2021 06:46:44 -0300 Subject: [PATCH] Hide internal stack when using pytest.approx() in bool context (#9394) This makes the error traceback point directly to the offending usage, rather than to the internal `Approx.__bool__` method. (cherry picked from commit 3ba9c01f9bfd442f2bcc4711e15612aa5b518cc3) --- src/_pytest/python_api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index 26f78c66a..cb72fde1e 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -101,6 +101,7 @@ class ApproxBase: ) def __bool__(self): + __tracebackhide__ = True raise AssertionError( "approx() is not supported in a boolean context.\nDid you mean: `assert a == approx(b)`?" )