Merge pull request #4985 from blueyed/assert-from_current

ExceptionInfo.from_current: assert current exception
This commit is contained in:
Daniel Hahler 2019-03-25 23:28:58 +01:00 committed by GitHub
commit b53bf44139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -413,6 +413,7 @@ class ExceptionInfo(object):
to the exception message/``__str__()``
"""
tup = sys.exc_info()
assert tup[0] is not None, "no current exception"
_striptext = ""
if exprinfo is None and isinstance(tup[1], AssertionError):
exprinfo = getattr(tup[1], "msg", None)

View File

@ -172,6 +172,10 @@ class TestExceptionInfo(object):
exci = _pytest._code.ExceptionInfo.from_current()
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):
def test_getsource(self):