Skip to content

Commit

Permalink
topotato: safeguard _codeloc == None
Browse files Browse the repository at this point in the history
Subclasses that don't have a `_codeloc` should overwrite this, but let's
safeguard anyway.

Signed-off-by: David Lamparter <[email protected]>
  • Loading branch information
eqvinox committed Sep 16, 2024
1 parent ac39a58 commit 969102e
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion topotato/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ def reportinfo(self): # -> Tuple[Union[py.path.local, str], int, str]:
Return the location the test item was yield-generated from, rather
than some place deep in the topotato logic.
"""
if self._codeloc is None:
return "???", 0, self.name

fspath = self._codeloc.filename
lineno = self._codeloc.lineno
return fspath, lineno, self.name
Expand Down Expand Up @@ -392,7 +395,7 @@ def _repr_failure(self, excinfo, style=None):
if reprcls:
return reprcls(excinfo)

if not hasattr(self, "_codeloc"):
if getattr(self, "_codeloc", None) is None:
return super().repr_failure(excinfo)

if isinstance(excinfo.value, _pytest.fixtures.FixtureLookupError):
Expand Down

0 comments on commit 969102e

Please sign in to comment.