Skip to content

Commit 8da6ecf

Browse files
committed
Fix CallInfo.__repr__ for unfinished call
Fixes pytest-dev#3554 Ref: pytest-dev#3560 Ref: pytest-dev#3562
1 parent 243d898 commit 8da6ecf

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

changelog/3554.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow ``CallInfo`` to have an unfinished state represented by having a ``None`` value in the ``result`` attribute.

src/_pytest/runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ def __repr__(self):
224224
if self.excinfo:
225225
status = "exception: %s" % str(self.excinfo.value)
226226
else:
227-
status = "result: %r" % (self.result,)
227+
result = getattr(self, "result", "<NOTSET>")
228+
status = "result: %r" % (result,)
228229
return "<CallInfo when=%r %s>" % (self.when, status)
229230

230231

testing/test_runner.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,21 @@ def test_callinfo():
493493
assert "result" in repr(ci)
494494
ci = runner.CallInfo(lambda: 0 / 0, "123")
495495
assert ci.when == "123"
496-
assert not hasattr(ci, "result")
496+
assert ci.result is None
497497
assert ci.excinfo
498498
assert "exc" in repr(ci)
499499

500500

501+
def test_callinfo_repr_while_running():
502+
def repr_while_running():
503+
f = sys._getframe().f_back
504+
assert "func" in f.f_locals
505+
assert repr(f.f_locals["self"]) == "<CallInfo when='when' result: '<NOTSET>'>"
506+
507+
ci = runner.CallInfo(repr_while_running, "when")
508+
assert repr(ci) == "<CallInfo when='when' result: None>"
509+
510+
501511
# design question: do we want general hooks in python files?
502512
# then something like the following functional tests makes sense
503513

0 commit comments

Comments
 (0)