Perform a "unicode aware" check for maximum recursion depth error
Avoid errors `UnicodeErrosr`s due non maximum recursion depth errors when checking for those errors.
This commit is contained in:
parent
0eb80bcb5a
commit
7ce5873da2
1
AUTHORS
1
AUTHORS
|
@ -61,6 +61,7 @@ Marc Schlaich
|
||||||
Mark Abramowitz
|
Mark Abramowitz
|
||||||
Markus Unterwaditzer
|
Markus Unterwaditzer
|
||||||
Martijn Faassen
|
Martijn Faassen
|
||||||
|
Martin Prusse
|
||||||
Matt Bachmann
|
Matt Bachmann
|
||||||
Michael Aquilina
|
Michael Aquilina
|
||||||
Michael Birtwell
|
Michael Birtwell
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
|
|
||||||
*
|
*
|
||||||
|
|
||||||
|
* 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.
|
* Fix ``pytest.mark.skip`` mark when used in strict mode.
|
||||||
Thanks `@pquentin`_ for the PR and `@RonnyPfannschmidt`_ for
|
Thanks `@pquentin`_ for the PR and `@RonnyPfannschmidt`_ for
|
||||||
showing how to fix the bug.
|
showing how to fix the bug.
|
||||||
|
@ -15,6 +19,11 @@
|
||||||
Thanks `@omarkohl`_ for the PR.
|
Thanks `@omarkohl`_ for the PR.
|
||||||
|
|
||||||
|
|
||||||
|
.. _#1506: https://github.com/pytest-dev/pytest/pull/1506
|
||||||
|
|
||||||
|
.. _@prusse-martin: https://github.com/prusse-martin
|
||||||
|
|
||||||
|
|
||||||
2.9.1
|
2.9.1
|
||||||
=====
|
=====
|
||||||
|
|
||||||
|
|
|
@ -579,9 +579,8 @@ class FormattedExcinfo(object):
|
||||||
if self.tbfilter:
|
if self.tbfilter:
|
||||||
traceback = traceback.filter()
|
traceback = traceback.filter()
|
||||||
recursionindex = None
|
recursionindex = None
|
||||||
if excinfo.errisinstance(RuntimeError):
|
if is_recursion_error(excinfo):
|
||||||
if "maximum recursion depth exceeded" in str(excinfo.value):
|
recursionindex = traceback.recursionindex()
|
||||||
recursionindex = traceback.recursionindex()
|
|
||||||
last = traceback[-1]
|
last = traceback[-1]
|
||||||
entries = []
|
entries = []
|
||||||
extraline = None
|
extraline = None
|
||||||
|
@ -793,3 +792,14 @@ def getrawcode(obj, trycall=True):
|
||||||
return x
|
return x
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
if sys.version_info[:2] >= (3, 5): # RecursionError introduced in 3.5
|
||||||
|
def is_recursion_error(excinfo):
|
||||||
|
return excinfo.errisinstance(RecursionError) # noqa
|
||||||
|
else:
|
||||||
|
def is_recursion_error(excinfo):
|
||||||
|
if not excinfo.errisinstance(RuntimeError):
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
return "maximum recursion depth exceeded" in str(excinfo.value)
|
||||||
|
except UnicodeError:
|
||||||
|
return False
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import _pytest
|
import _pytest
|
||||||
import py
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest._code.code import FormattedExcinfo, ReprExceptionInfo
|
from _pytest._code.code import ExceptionInfo, FormattedExcinfo, ReprExceptionInfo
|
||||||
|
|
||||||
queue = py.builtin._tryimport('queue', 'Queue')
|
queue = py.builtin._tryimport('queue', 'Queue')
|
||||||
|
|
||||||
|
@ -909,3 +909,19 @@ raise ValueError()
|
||||||
assert tw.lines[14] == "E ValueError"
|
assert tw.lines[14] == "E ValueError"
|
||||||
assert tw.lines[15] == ""
|
assert tw.lines[15] == ""
|
||||||
assert tw.lines[16].endswith("mod.py:9: ValueError")
|
assert tw.lines[16].endswith("mod.py:9: ValueError")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("style", ["short", "long"])
|
||||||
|
@pytest.mark.parametrize("encoding", [None, "utf8", "utf16"])
|
||||||
|
def test_repr_traceback_with_unicode(style, encoding):
|
||||||
|
msg = u'☹'
|
||||||
|
if encoding is not None:
|
||||||
|
msg = msg.encode(encoding)
|
||||||
|
try:
|
||||||
|
raise RuntimeError(msg)
|
||||||
|
except RuntimeError:
|
||||||
|
e_info = ExceptionInfo()
|
||||||
|
formatter = FormattedExcinfo(style=style)
|
||||||
|
repr_traceback = formatter.repr_traceback(e_info)
|
||||||
|
assert repr_traceback is not None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue