py.test version: 3.6.0
Python version: 3.6.4
The result attribute of CallInfo objects is assigned in __init__ as the result of calling the test function. This means that result is only defined after the test function has finished executing.
If however, the test function extracts local variables from the stack (and does anything causing __repr__ to be called on them) this causes an AttributeError since CallInfo.__repr__ expects result to be defined.
Minimum example:
import sys
from traceback import print_list, StackSummary, walk_stack
def print_stack():
stack = StackSummary.extract(walk_stack(sys._getframe().f_back), capture_locals=True)
stack.reverse()
print_list(stack)
def test_bla():
print_stack()
# ^ This will crash with `AttributeError: 'CallInfo' object has no attribute 'result'`
assert 1 == 1
py.test version: 3.6.0
Python version: 3.6.4
The
resultattribute ofCallInfoobjects is assigned in__init__as the result of calling the test function. This means thatresultis only defined after the test function has finished executing.If however, the test function extracts local variables from the stack (and does anything causing
__repr__to be called on them) this causes an AttributeError sinceCallInfo.__repr__expectsresultto be defined.Minimum example: