Skip to content

Commit

Permalink
Fix CallInfo.__repr__ for unfinished call
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Nov 13, 2018
1 parent 243d898 commit 27dab4e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/3554.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``CallInfo.__repr__`` for when the call is not finished yet.
3 changes: 2 additions & 1 deletion src/_pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ def __repr__(self):
if self.excinfo:
status = "exception: %s" % str(self.excinfo.value)
else:
status = "result: %r" % (self.result,)
result = getattr(self, "result", "<NOTSET>")
status = "result: %r" % (result,)
return "<CallInfo when=%r %s>" % (self.when, status)


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

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


def test_callinfo_repr_while_running():
def repr_while_running():
f = sys._getframe().f_back
assert "func" in f.f_locals
assert repr(f.f_locals["self"]) == "<CallInfo when='when' result: '<NOTSET>'>"

ci = runner.CallInfo(repr_while_running, "when")
assert repr(ci) == "<CallInfo when='when' result: None>"


# design question: do we want general hooks in python files?
# then something like the following functional tests makes sense

Expand Down

0 comments on commit 27dab4e

Please sign in to comment.