Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔊 Add info about one reason for RuntimeError, which is otherwise difficult to catch #149

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion devtools/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down