Skip to content

CallInfo.__repr__ raises AttributeError if called before __init__ is finished #3554

@ulope

Description

@ulope

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributortype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions