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

Conversation

tiangolo
Copy link
Sponsor

@tiangolo tiangolo commented Dec 3, 2023

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

When there's a multiline error message in an assert, insert_assert can't find the frame, probably a quirk of Python. This adds a message showing what might be the problem.

Here's an example test that breaks with the RuntimeError:

def test_multiline_error_message(insert_assert):
    assert True, (
        "This error message has "
        "more than one line."
    )
    insert_assert(1)

The new error will show:

RuntimeError: insert_assert() was unable to find the frame from which it was called.

Sometimes this happens when there's an assert statement with a an error message with multiple lines, like: 

assert foo == bar, (
    'foo should be '
    'equal to bar'
)

You can try commenting out that assert statement while you run insert_assert() and then uncommenting it afterwards.

insert_assert was called with:
1

Copy link

codecov bot commented Dec 3, 2023

Codecov Report

Merging #149 (af33c65) into main (ec406ff) will not change coverage.
The diff coverage is n/a.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #149   +/-   ##
=======================================
  Coverage   96.29%   96.29%           
=======================================
  Files           8        8           
  Lines         729      729           
  Branches      111      111           
=======================================
  Hits          702      702           
  Misses         21       21           
  Partials        6        6           
Files Coverage Δ
devtools/pytest_plugin.py 88.13% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ec406ff...af33c65. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant