Improve/revisit CallInfo.__repr__ (#6007)
This commit is contained in:
		
						commit
						9b673bcc44
					
				|  | @ -236,16 +236,9 @@ class CallInfo: | ||||||
|         return cls(start=start, stop=stop, when=when, result=result, excinfo=excinfo) |         return cls(start=start, stop=stop, when=when, result=result, excinfo=excinfo) | ||||||
| 
 | 
 | ||||||
|     def __repr__(self): |     def __repr__(self): | ||||||
|         if self.excinfo is not None: |         if self.excinfo is None: | ||||||
|             status = "exception" |             return "<CallInfo when={!r} result: {!r}>".format(self.when, self._result) | ||||||
|             value = self.excinfo.value |         return "<CallInfo when={!r} excinfo={!r}>".format(self.when, self.excinfo) | ||||||
|         else: |  | ||||||
|             # TODO: investigate unification |  | ||||||
|             value = repr(self._result) |  | ||||||
|             status = "result" |  | ||||||
|         return "<CallInfo when={when!r} {status}: {value}>".format( |  | ||||||
|             when=self.when, value=value, status=status |  | ||||||
|         ) |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def pytest_runtest_makereport(item, call): | def pytest_runtest_makereport(item, call): | ||||||
|  |  | ||||||
|  | @ -483,13 +483,22 @@ def test_callinfo(): | ||||||
|     assert ci.result == 0 |     assert ci.result == 0 | ||||||
|     assert "result" in repr(ci) |     assert "result" in repr(ci) | ||||||
|     assert repr(ci) == "<CallInfo when='123' result: 0>" |     assert repr(ci) == "<CallInfo when='123' result: 0>" | ||||||
|  |     assert str(ci) == "<CallInfo when='123' result: 0>" | ||||||
| 
 | 
 | ||||||
|     ci = runner.CallInfo.from_call(lambda: 0 / 0, "123") |     ci = runner.CallInfo.from_call(lambda: 0 / 0, "123") | ||||||
|     assert ci.when == "123" |     assert ci.when == "123" | ||||||
|     assert not hasattr(ci, "result") |     assert not hasattr(ci, "result") | ||||||
|     assert repr(ci) == "<CallInfo when='123' exception: division by zero>" |     assert repr(ci) == "<CallInfo when='123' excinfo={!r}>".format(ci.excinfo) | ||||||
|  |     assert str(ci) == repr(ci) | ||||||
|     assert ci.excinfo |     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) == "<CallInfo when='call' excinfo={!r}>".format(ci.excinfo) | ||||||
|  |     assert "\n" not in repr(ci) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # design question: do we want general hooks in python files? | # design question: do we want general hooks in python files? | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue