Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions src/_pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,9 @@ def from_call(cls, func, when, reraise=None):
return cls(start=start, stop=stop, when=when, result=result, excinfo=excinfo)

def __repr__(self):
if self.excinfo is not None:
status = "exception"
value = self.excinfo.value
else:
# TODO: investigate unification
value = repr(self._result)
status = "result"
return "<CallInfo when={when!r} {status}: {value}>".format(
when=self.when, value=value, status=status
)
if self.excinfo is None:
return "<CallInfo when={!r} result: {!r}>".format(self.when, self._result)
return "<CallInfo when={!r} excinfo={!r}>".format(self.when, self.excinfo)


def pytest_runtest_makereport(item, call):
Expand Down
13 changes: 11 additions & 2 deletions testing/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,22 @@ def test_callinfo():
assert ci.result == 0
assert "result" in repr(ci)
assert repr(ci) == "<CallInfo when='123' result: 0>"
assert str(ci) == "<CallInfo when='123' result: 0>"

ci = runner.CallInfo.from_call(lambda: 0 / 0, "123")
assert ci.when == "123"
assert not hasattr(ci, "result")
assert repr(ci) == "<CallInfo when='123' exception: division by zero>"
assert repr(ci) == "<CallInfo when='123' excinfo={!r}>".format(ci.excinfo)
assert str(ci) == repr(ci)
assert ci.excinfo
assert "exc" in repr(ci)

# Newlines are escaped.
def raise_assertion():
assert 0, "assert_msg"

ci = runner.CallInfo.from_call(raise_assertion, "call")
assert repr(ci) == "<CallInfo when='call' excinfo={!r}>".format(ci.excinfo)
assert "\n" not in repr(ci)


# design question: do we want general hooks in python files?
Expand Down