Skip to content

Fix INTERNALERROR when skipping an item without a line number - #14855

Open
RonnyPfannschmidt wants to merge 2 commits into
pytest-dev:mainfrom
RonnyPfannschmidt:fix/skip-location-without-line
Open

RonnyPfannschmidt wants to merge 2 commits into
pytest-dev:mainfrom
RonnyPfannschmidt:fix/skip-location-without-line

Conversation

@RonnyPfannschmidt

@RonnyPfannschmidt RonnyPfannschmidt commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Note

Stack: #14855 -> #14856 -> #14769 -> #14857 -> #14858. Bottom of the chain,
depends on nothing.

TestReport.from_item_and_call asserted reportinfo() yields a line number.
Items which cannot point at a line — non-Python items legitimately report
None — crash with an INTERNALERROR when skipped via a marker.

Reports the location without a line instead.

Standalone bug fix, reproducible on main with any custom Item; it sits at
the bottom of the chain only because #14858 needs it, where a non-Python
definition can carry pytest.param(..., marks=pytest.mark.skip(...)).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash in TestReport.from_item_and_call when a skipped Item’s reportinfo() has no line number (None), which can happen for non-Python items.

Changes:

  • Adjust skip longrepr construction to avoid asserting a line number is present when _use_item_location is set.
  • Add a regression test exercising a custom Item that reports no line number and is skipped via a marker.
  • Add a changelog entry documenting the fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
testing/test_skipping.py Adds regression coverage for skipping an Item whose reportinfo() line is None.
src/_pytest/reports.py Updates skip-report longrepr construction to avoid crashing when reportinfo() has no line number.
changelog/14855.bugfix.rst Documents the bugfix in the changelog.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/_pytest/reports.py
Comment on lines 419 to +423
path, line = item.reportinfo()[:2]
assert line is not None
longrepr = (os.fspath(path), line + 1, r.message)
# Items which cannot point at a line -- non-Python items may
# legitimately report None -- get the location without one.
lineno = line + 1 if line is not None else -1
longrepr = (os.fspath(path), lineno, r.message)
Comment thread testing/test_skipping.py
Comment on lines +1396 to +1409
class MyItem(pytest.Item):
def runtest(self):
raise AssertionError("should not run")

def pytest_collect_file(file_path, parent):
item = MyItem.from_parent(name="foo", parent=parent)
item.add_marker(pytest.mark.skip(reason="no line here"))
return item
"""
)
result = pytester.runpytest("-rs")
assert "INTERNALERROR" not in result.stdout.str()
result.stdout.fnmatch_lines(["*no line here*"])
result.assert_outcomes(skipped=1)
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the fix/skip-location-without-line branch from 1f5ef21 to 2001520 Compare September 15, 2026 11:51
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the fix/skip-location-without-line branch from 2001520 to ede7c31 Compare September 23, 2026 07:00
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the fix/skip-location-without-line branch 2 times, most recently from df6c831 to f3f4e68 Compare October 11, 2026 07:26
TestReport.from_item_and_call asserted reportinfo() yields a line
number. Items which cannot point at a line -- non-Python items
legitimately report None -- crashed with an INTERNALERROR when skipped
via a marker. Report the location without a line instead.
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the fix/skip-location-without-line branch from f3f4e68 to 6d680f1 Compare October 14, 2026 20:28

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how the automated test exercise the code. It's a python object, it should have a line ? Also we only check that there isn't an internal error and not the actual output

Comment thread src/_pytest/reports.py
Comment on lines +447 to +448
# Items which cannot point at a line -- non-Python items may
# legitimately report None -- get the location without one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Items which cannot point at a line -- non-Python items may
# legitimately report None -- get the location without one.
# non-Python items may legitimately have no line to point at.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants