-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Eliminate "during the above exception" in py3 #79
Eliminate "during the above exception" in py3 #79
Conversation
This supports Python 2 and Python 3, and dramatically reduces the number of lines that show up in tracebacks in Python 3.
raise AssertionError(*e.args) | ||
err = e | ||
if err is not None: | ||
raise AssertionError(*err.args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use else:
with the try
to return and just raise AssertionError
in the end then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just remembered that Python 3 (can't find a link now) will delete the exception value caught by as
after leaving the except
block; that is done to avoiding leaking the frames in the traceback value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@blueyed yeah this is constructed this way because if the assertion is raised inside the
except
block then you still get the during the above exception
message/tb. If the e
isn't assigned to some other variable then it is a NameError in py3. If this project didn't support py2 we could theoretically do raise ... from None
but that's illegal before py3 and it didn't actually work correctly for me in my testing.
Thanks @quodlibetor for the PR! I will merge this and make a new release tomorrow. |
Hi @quodlibetor, Tried your branch locally: def test(mocker):
m = mocker.Mock()
m('fo')
m.assert_called_with('')
So it is missing catching the errors around the internal asserts of |
This supports Python 2 and Python 3, and dramatically reduces the number of
lines that show up in tracebacks in Python 3.