ExceptionInfo.from_current: assert current exception
This commit is contained in:
parent
15d608867d
commit
2d690b83bf
|
@ -413,6 +413,7 @@ class ExceptionInfo(object):
|
||||||
to the exception message/``__str__()``
|
to the exception message/``__str__()``
|
||||||
"""
|
"""
|
||||||
tup = sys.exc_info()
|
tup = sys.exc_info()
|
||||||
|
assert tup[0] is not None, "no current exception"
|
||||||
_striptext = ""
|
_striptext = ""
|
||||||
if exprinfo is None and isinstance(tup[1], AssertionError):
|
if exprinfo is None and isinstance(tup[1], AssertionError):
|
||||||
exprinfo = getattr(tup[1], "msg", None)
|
exprinfo = getattr(tup[1], "msg", None)
|
||||||
|
|
|
@ -172,6 +172,10 @@ class TestExceptionInfo(object):
|
||||||
exci = _pytest._code.ExceptionInfo.from_current()
|
exci = _pytest._code.ExceptionInfo.from_current()
|
||||||
assert exci.getrepr()
|
assert exci.getrepr()
|
||||||
|
|
||||||
|
def test_from_current_with_missing(self):
|
||||||
|
with pytest.raises(AssertionError, match="no current exception"):
|
||||||
|
_pytest._code.ExceptionInfo.from_current()
|
||||||
|
|
||||||
|
|
||||||
class TestTracebackEntry(object):
|
class TestTracebackEntry(object):
|
||||||
def test_getsource(self):
|
def test_getsource(self):
|
||||||
|
|
Loading…
Reference in New Issue