-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Fix repr_traceback
to work with unicode errors
#1506
Fix repr_traceback
to work with unicode errors
#1506
Conversation
Thanks for porting this PR from bitbucket @prusse-martin! Could you take a look at the failing tests? Also, please add a changelog entry and yourself to |
My bad. When checking travis-ci to see if some new error have been introduced got confused and ended looking at the build results of master. |
No worries! (note, make sure to comment something here when you think the PR is ready for review again, because GitHub does not send new notification e-mails when commits are added, only for new comments on the PR). |
The tests are passing. I actually have mixed felling about the way I did it. The other possible way is to use something like:
Any suggestions? |
After some thought I realized that we only need to check if the exception was a "maximum recursion depth" exception, we don't need to try to come up with a generic solution to convert a solution to string first. With that in mind how about: # code.py
if sys.version_info[:2] >= (3, 5): # RecursionError introduced in 3.5
def is_recursion_error(exception):
return isinstance(exception, RecursionError)
else:
def is_recursion_error(exception):
if not isinstance(exception, RuntimeError):
return False
try:
return "maximum recursion depth exceeded" in str(exception)
except UnicodeDecodeError:
return False
class FormattedExcinfo(object):
...
def repr_traceback(self, excinfo):
traceback = excinfo.traceback
if self.tbfilter:
traceback = traceback.filter()
recursionindex = None
if is_recursion_error(excinfo.value):
recursionindex = traceback.recursionindex()
... The line What do you think? |
@@ -7,6 +7,9 @@ | |||
|
|||
* | |||
|
|||
* Fix maximum recursion depth detection when raised error class is not aware |
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.
Please add a reference back to the PR, something along the lines:
* Fix maximum recursion depth detection when raised error class is not aware
of unicode/encoded bytes. Thanks `@prusse-martin`_ for the PR (`#1506`_).
.. _#1506: https://github.com/pytest-dev/pytest/pull/1506
.. _@prusse-martin: https://github.com/prusse-martin
I thought something like your proposed code. I just felt a bit awkward about explicitly checking the version at that moment. |
I would say that's OK, specially because |
Avoid errors `UnicodeErrosr`s due non maximum recursion depth errors when checking for those errors.
bc62d51
to
7ce5873
Compare
Done. The coverage results got down a bit due the version dependent implementation (the tests for coverage have been run with python 3.4). |
Thanks a lot Martin! |
2.9.2 ===== **Bug Fixes** * fix `#510`_: skip tests where one parameterize dimension was empty thanks Alex Stapleton for the Report and `@RonnyPfannschmidt`_ for the PR * Fix Xfail does not work with condition keyword argument. Thanks `@astraw38`_ for reporting the issue (`#1496`_) and `@tomviner`_ for PR the (`#1524`_). * Fix win32 path issue when puttinging custom config file with absolute path in ``pytest.main("-c your_absolute_path")``. * Fix maximum recursion depth detection when raised error class is not aware of unicode/encoded bytes. Thanks `@prusse-martin`_ for the PR (`#1506`_). * Fix ``pytest.mark.skip`` mark when used in strict mode. Thanks `@pquentin`_ for the PR and `@RonnyPfannschmidt`_ for showing how to fix the bug. * Minor improvements and fixes to the documentation. Thanks `@omarkohl`_ for the PR. * Fix ``--fixtures`` to show all fixture definitions as opposed to just one per fixture name. Thanks to `@hackebrot`_ for the PR. .. _#510: pytest-dev/pytest#510 .. _#1506: pytest-dev/pytest#1506 .. _#1496: https://github.com/pytest-dev/pytest/issue/1496 .. _#1524: https://github.com/pytest-dev/pytest/issue/1524 .. _@prusse-martin: https://github.com/prusse-martin .. _@astraw38: https://github.com/astraw38
Properly handle errors with unicode messages (could cause unicode decode errors when converting to
str
).Added test to check if different encodings in raised error will not cause the code to fail.