diff --git a/src/pytest_markdown_docs/plugin.py b/src/pytest_markdown_docs/plugin.py index cad6b4e..027396c 100644 --- a/src/pytest_markdown_docs/plugin.py +++ b/src/pytest_markdown_docs/plugin.py @@ -115,7 +115,10 @@ def repr_failure( True # start capturing frames the first time we enter user code ) line = ( - rawlines[frame_summary.lineno - 1] if frame_summary.lineno else "" + rawlines[frame_summary.lineno - 1] + if frame_summary.lineno is not None + and 1 <= frame_summary.lineno <= len(rawlines) + else "" ) else: lineno = frame_summary.lineno or 0