From 0ffb86d0263dbb3f974f74d703f93c328baeda68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sun, 3 Dec 2023 15:19:32 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=8A=20Add=20info=20to=20potential?= =?UTF-8?q?=20reason=20for=20RuntimeError,=20otherwise=20difficult=20to=20?= =?UTF-8?q?catch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- devtools/pytest_plugin.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/devtools/pytest_plugin.py b/devtools/pytest_plugin.py index f80efd3..1d1812b 100644 --- a/devtools/pytest_plugin.py +++ b/devtools/pytest_plugin.py @@ -47,7 +47,13 @@ def insert_assert(value: Any) -> int: if ex.node is None: # pragma: no cover python_code = format_code(str(custom_repr(value))) raise RuntimeError( - f'insert_assert() was unable to find the frame from which it was called, called with:\n{python_code}' + 'insert_assert() was unable to find the frame from which it was called.\n\n' + "Sometimes this happens when there's an assert statement with a an error " + 'message with multiple lines, like: ' + "\n\nassert foo == bar, (\n 'foo should be\n equal to bar'\n)\n\n" + 'You can try commenting out that assert statement while you run ' + 'insert_assert() and then uncommenting it afterwards.\n\n' + f'insert_assert was called with:\n{python_code}' ) ast_arg = ex.node.args[0] # type: ignore[attr-defined] if isinstance(ast_arg, ast.Name): From af33c6586079d3adb86a8b6779b55fe4889949bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sun, 3 Dec 2023 15:25:34 +0100 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=8A=20Tweak=20error=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- devtools/pytest_plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devtools/pytest_plugin.py b/devtools/pytest_plugin.py index 1d1812b..774ea91 100644 --- a/devtools/pytest_plugin.py +++ b/devtools/pytest_plugin.py @@ -50,7 +50,7 @@ def insert_assert(value: Any) -> int: 'insert_assert() was unable to find the frame from which it was called.\n\n' "Sometimes this happens when there's an assert statement with a an error " 'message with multiple lines, like: ' - "\n\nassert foo == bar, (\n 'foo should be\n equal to bar'\n)\n\n" + "\n\nassert foo == bar, (\n 'foo should be '\n 'equal to bar'\n)\n\n" 'You can try commenting out that assert statement while you run ' 'insert_assert() and then uncommenting it afterwards.\n\n' f'insert_assert was called with:\n{python_code}'