Merge pull request #4652 from blueyed/RunResult-repr

Add __repr__ for RunResult
This commit is contained in:
Daniel Hahler 2019-02-09 01:26:24 +01:00 committed by GitHub
commit ed01dc6567
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -398,6 +398,12 @@ class RunResult(object):
self.stderr = LineMatcher(errlines) self.stderr = LineMatcher(errlines)
self.duration = duration self.duration = duration
def __repr__(self):
return (
"<RunResult ret=%r len(stdout.lines)=%d len(stderr.lines)=%d duration=%.2fs>"
% (self.ret, len(self.stdout.lines), len(self.stderr.lines), self.duration)
)
def parseoutcomes(self): def parseoutcomes(self):
"""Return a dictionary of outcomestring->num from parsing the terminal """Return a dictionary of outcomestring->num from parsing the terminal
output that the test process produced. output that the test process produced.

View File

@ -127,6 +127,17 @@ def test_runresult_assertion_on_xpassed(testdir):
assert result.ret == 0 assert result.ret == 0
def test_runresult_repr():
from _pytest.pytester import RunResult
assert (
repr(
RunResult(ret="ret", outlines=[""], errlines=["some", "errors"], duration=1)
)
== "<RunResult ret='ret' len(stdout.lines)=1 len(stderr.lines)=2 duration=1.00s>"
)
def test_xpassed_with_strict_is_considered_a_failure(testdir): def test_xpassed_with_strict_is_considered_a_failure(testdir):
testdir.makepyfile( testdir.makepyfile(
""" """