add checks to make sure crash entries are not none where they should not be

This commit is contained in:
Felix Hofstätter 2023-03-12 16:39:26 +01:00
parent e6e36c2dee
commit 7f95c9c3d7
3 changed files with 11 additions and 1 deletions

View File

@ -650,13 +650,18 @@ class ExceptionInfo(Generic[E]):
Added the ``chain`` parameter.
"""
if style == "native":
r = self._getreprcrash()
if r is None:
raise ValueError(
"There should always be a non-hidden traceback entry for the top level function."
)
return ReprExceptionInfo(
reprtraceback=ReprTracebackNative(
traceback.format_exception(
self.type, self.value, self.traceback[0]._rawentry
)
),
reprcrash=self._getreprcrash(),
reprcrash=r,
)
fmt = FormattedExcinfo(

View File

@ -347,6 +347,10 @@ class TestReport(BaseReport):
elif isinstance(excinfo.value, skip.Exception):
outcome = "skipped"
r = excinfo._getreprcrash()
if r is None:
raise ValueError(
"There should always be a traceback entry for skipping a test."
)
if excinfo.value._use_item_location:
path, line = item.reportinfo()[:2]
assert line is not None

View File

@ -294,6 +294,7 @@ class TestTraceback_f_g_h:
excinfo = pytest.raises(ValueError, f)
tb = excinfo.traceback
entry = tb.getcrashentry()
assert entry is not None
co = _pytest._code.Code.from_function(h)
assert entry.frame.code.path == co.path
assert entry.lineno == co.firstlineno + 1