Skip to content

Commit 9bcbf55

Browse files
committed
Add __repr__ for RunResult
1 parent a131cd6 commit 9bcbf55

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/_pytest/pytester.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,12 @@ def __init__(self, ret, outlines, errlines, duration):
398398
self.stderr = LineMatcher(errlines)
399399
self.duration = duration
400400

401+
def __repr__(self):
402+
return (
403+
"<RunResult ret=%r len(stdout.lines)=%d len(stderr.lines)=%d duration=%.2fs>"
404+
% (self.ret, len(self.stdout.lines), len(self.stderr.lines), self.duration)
405+
)
406+
401407
def parseoutcomes(self):
402408
"""Return a dictionary of outcomestring->num from parsing the terminal
403409
output that the test process produced.

testing/test_pytester.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ def test_potato():
127127
assert result.ret == 0
128128

129129

130+
def test_runresult_repr():
131+
from _pytest.pytester import RunResult
132+
133+
assert (
134+
repr(
135+
RunResult(ret="ret", outlines=[""], errlines=["some", "errors"], duration=1)
136+
)
137+
== "<RunResult ret='ret' len(stdout.lines)=1 len(stderr.lines)=2 duration=1.00s>"
138+
)
139+
140+
130141
def test_xpassed_with_strict_is_considered_a_failure(testdir):
131142
testdir.makepyfile(
132143
"""

0 commit comments

Comments
 (0)