Remove ExceptionInfo.__str__, falling back to __repr__ (#5413)
Remove ExceptionInfo.__str__, falling back to __repr__
This commit is contained in:
		
						commit
						9f5c356784
					
				|  | @ -0,0 +1,2 @@ | ||||||
|  | ``ExceptionInfo`` objects (returned by ``pytest.raises``) now have the same ``str`` representation as ``repr``, which | ||||||
|  | avoids some confusion when users use ``print(e)`` to inspect the object. | ||||||
|  | @ -534,13 +534,6 @@ class ExceptionInfo: | ||||||
|         ) |         ) | ||||||
|         return fmt.repr_excinfo(self) |         return fmt.repr_excinfo(self) | ||||||
| 
 | 
 | ||||||
|     def __str__(self): |  | ||||||
|         if self._excinfo is None: |  | ||||||
|             return repr(self) |  | ||||||
|         entry = self.traceback[-1] |  | ||||||
|         loc = ReprFileLocation(entry.path, entry.lineno + 1, self.exconly()) |  | ||||||
|         return str(loc) |  | ||||||
| 
 |  | ||||||
|     def match(self, regexp): |     def match(self, regexp): | ||||||
|         """ |         """ | ||||||
|         Check whether the regular expression 'regexp' is found in the string |         Check whether the regular expression 'regexp' is found in the string | ||||||
|  |  | ||||||
|  | @ -333,18 +333,10 @@ def test_excinfo_exconly(): | ||||||
|     assert msg.endswith("world") |     assert msg.endswith("world") | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def test_excinfo_repr(): | def test_excinfo_repr_str(): | ||||||
|     excinfo = pytest.raises(ValueError, h) |     excinfo = pytest.raises(ValueError, h) | ||||||
|     s = repr(excinfo) |     assert repr(excinfo) == "<ExceptionInfo ValueError tblen=4>" | ||||||
|     assert s == "<ExceptionInfo ValueError tblen=4>" |     assert str(excinfo) == "<ExceptionInfo ValueError tblen=4>" | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| def test_excinfo_str(): |  | ||||||
|     excinfo = pytest.raises(ValueError, h) |  | ||||||
|     s = str(excinfo) |  | ||||||
|     assert s.startswith(__file__[:-9])  # pyc file and $py.class |  | ||||||
|     assert s.endswith("ValueError") |  | ||||||
|     assert len(s.split(":")) >= 3  # on windows it's 4 |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def test_excinfo_for_later(): | def test_excinfo_for_later(): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue