Merge pull request #4444 from RonnyPfannschmidt/fix-4386-2

fix #4386 - handle uninitialized exceptioninfo in repr/str
This commit is contained in:
Bruno Oliveira
2018-11-23 12:40:41 -02:00
committed by GitHub
3 changed files with 29 additions and 4 deletions

View File

@@ -33,6 +33,23 @@ class TestRaises(object):
except pytest.raises.Exception:
pass
def test_raises_repr_inflight(self):
"""Ensure repr() on an exception info inside a pytest.raises with block works (#4386)"""
class E(Exception):
pass
with pytest.raises(E) as excinfo:
# this test prints the inflight uninitialized object
# using repr and str as well as pprint to demonstrate
# it works
print(str(excinfo))
print(repr(excinfo))
import pprint
pprint.pprint(excinfo)
raise E()
def test_raises_as_contextmanager(self, testdir):
testdir.makepyfile(
"""