From 9bcbf552d6a3cf7eb18299a1e18b26b25eb6432b Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 18 Jan 2019 17:35:49 +0100 Subject: [PATCH] Add __repr__ for RunResult --- src/_pytest/pytester.py | 6 ++++++ testing/test_pytester.py | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 9cadd2f9d..26859e660 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -398,6 +398,12 @@ class RunResult(object): self.stderr = LineMatcher(errlines) self.duration = duration + def __repr__(self): + return ( + "" + % (self.ret, len(self.stdout.lines), len(self.stderr.lines), self.duration) + ) + def parseoutcomes(self): """Return a dictionary of outcomestring->num from parsing the terminal output that the test process produced. diff --git a/testing/test_pytester.py b/testing/test_pytester.py index d14fbd18e..675108460 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -127,6 +127,17 @@ def test_runresult_assertion_on_xpassed(testdir): assert result.ret == 0 +def test_runresult_repr(): + from _pytest.pytester import RunResult + + assert ( + repr( + RunResult(ret="ret", outlines=[""], errlines=["some", "errors"], duration=1) + ) + == "" + ) + + def test_xpassed_with_strict_is_considered_a_failure(testdir): testdir.makepyfile( """