Merge pull request #4381 from blueyed/callinfo-repr

Fix CallInfo.__repr__ for unfinished call
This commit is contained in:
Daniel Hahler 2018-11-13 18:13:58 +01:00 committed by GitHub
commit b7863a5f48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -0,0 +1 @@
Fix ``CallInfo.__repr__`` for when the call is not finished yet.

View File

@ -224,7 +224,8 @@ class CallInfo(object):
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)

View File

@ -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