Skip to content

Commit

Permalink
Fix internal error when trying to detect the start of a recursive tra…
Browse files Browse the repository at this point in the history
…ceback.

Fix pytest-dev#2486
  • Loading branch information
nicoddemus committed Jun 9, 2017
1 parent b2d7c26 commit aab5dc7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions _pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,11 @@ def _truncate_recursive_traceback(self, traceback):
).format(exc_type=type(e).__name__, exc_msg=safe_str(e), max_frames=max_frames, total=len(traceback))
traceback = traceback[:max_frames] + traceback[-max_frames:]
else:
extraline = "!!! Recursion detected (same locals & position)"
traceback = traceback[:recursionindex + 1]
if recursionindex is not None:
extraline = "!!! Recursion detected (same locals & position)"
traceback = traceback[:recursionindex + 1]
else:
extraline = None

return traceback, extraline

Expand Down
1 change: 1 addition & 0 deletions changelog/2486.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix internal error when trying to detect the start of a recursive traceback.
18 changes: 18 additions & 0 deletions testing/code/test_excinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,3 +1173,21 @@ def b(x):
'*The following exception happened*',
'*ValueError: The truth value of an array*',
])


def test_no_recursion_index_on_recursion_error():
"""
Ensure that we don't break in case we can't find the recursion index
during a recursion error (#2486).
"""
try:
class RecursionDepthError(object):
def __getattr__(self, attr):
return getattr(self, '_' + attr)

RecursionDepthError().trigger
assert 0
except:
from _pytest._code.code import ExceptionInfo
exc_info = ExceptionInfo()
assert 'maximum recursion' in str(exc_info.getrepr())

0 comments on commit aab5dc7

Please sign in to comment.