Skip to content

Fix CallInfo.__repr__ for unfinished call #4381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2018
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
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,)
Copy link
Contributor Author

@blueyed blueyed Nov 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RonnyPfannschmidt
I think compat.NOTSET is not needed here?!
(as outlined in #3560 (comment))

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