From 15f956869479a60b1c39f72309e9a0e7b75f1689 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 19 Oct 2019 11:05:12 +0200 Subject: [PATCH] Improve/revisit CallInfo.__repr__ --- src/_pytest/runner.py | 13 +++---------- testing/test_runner.py | 13 +++++++++++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/_pytest/runner.py b/src/_pytest/runner.py index fce4c1e3f..29f9658ee 100644 --- a/src/_pytest/runner.py +++ b/src/_pytest/runner.py @@ -236,16 +236,9 @@ class CallInfo: return cls(start=start, stop=stop, when=when, result=result, excinfo=excinfo) def __repr__(self): - if self.excinfo is not None: - status = "exception" - value = self.excinfo.value - else: - # TODO: investigate unification - value = repr(self._result) - status = "result" - return "".format( - when=self.when, value=value, status=status - ) + if self.excinfo is None: + return "".format(self.when, self._result) + return "".format(self.when, self.excinfo) def pytest_runtest_makereport(item, call): diff --git a/testing/test_runner.py b/testing/test_runner.py index 2d6b8476c..d2ce5d0bc 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -483,13 +483,22 @@ def test_callinfo(): assert ci.result == 0 assert "result" in repr(ci) assert repr(ci) == "" + assert str(ci) == "" ci = runner.CallInfo.from_call(lambda: 0 / 0, "123") assert ci.when == "123" assert not hasattr(ci, "result") - assert repr(ci) == "" + assert repr(ci) == "".format(ci.excinfo) + assert str(ci) == repr(ci) assert ci.excinfo - assert "exc" in repr(ci) + + # Newlines are escaped. + def raise_assertion(): + assert 0, "assert_msg" + + ci = runner.CallInfo.from_call(raise_assertion, "call") + assert repr(ci) == "".format(ci.excinfo) + assert "\n" not in repr(ci) # design question: do we want general hooks in python files?