Fix CallInfo.__repr__ for unfinished call
Fixes https://github.com/pytest-dev/pytest/issues/3554 Ref: https://github.com/pytest-dev/pytest/pull/3560 Ref: https://github.com/pytest-dev/pytest/pull/3562
This commit is contained in:
parent
243d898b38
commit
27dab4e05f
|
@ -0,0 +1 @@
|
||||||
|
Fix ``CallInfo.__repr__`` for when the call is not finished yet.
|
|
@ -224,7 +224,8 @@ class CallInfo(object):
|
||||||
if self.excinfo:
|
if self.excinfo:
|
||||||
status = "exception: %s" % str(self.excinfo.value)
|
status = "exception: %s" % str(self.excinfo.value)
|
||||||
else:
|
else:
|
||||||
status = "result: %r" % (self.result,)
|
result = getattr(self, "result", "<NOTSET>")
|
||||||
|
status = "result: %r" % (result,)
|
||||||
return "<CallInfo when=%r %s>" % (self.when, status)
|
return "<CallInfo when=%r %s>" % (self.when, status)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -491,13 +491,26 @@ def test_callinfo():
|
||||||
assert ci.when == "123"
|
assert ci.when == "123"
|
||||||
assert ci.result == 0
|
assert ci.result == 0
|
||||||
assert "result" in repr(ci)
|
assert "result" in repr(ci)
|
||||||
|
assert repr(ci) == "<CallInfo when='123' result: 0>"
|
||||||
|
|
||||||
ci = runner.CallInfo(lambda: 0 / 0, "123")
|
ci = runner.CallInfo(lambda: 0 / 0, "123")
|
||||||
assert ci.when == "123"
|
assert ci.when == "123"
|
||||||
assert not hasattr(ci, "result")
|
assert not hasattr(ci, "result")
|
||||||
|
assert repr(ci) == "<CallInfo when='123' exception: division by zero>"
|
||||||
assert ci.excinfo
|
assert ci.excinfo
|
||||||
assert "exc" in repr(ci)
|
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?
|
# design question: do we want general hooks in python files?
|
||||||
# then something like the following functional tests makes sense
|
# then something like the following functional tests makes sense
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue