Visitar URL original
Move collection error abort from pytest_runtestloop to pytest_collection by megacodes24 · Pull Request #15384 · pytest-dev/pytest · GitHub
Skip to content

Move collection error abort from pytest_runtestloop to pytest_collection - #15384

Open
megacodes24 wants to merge 1 commit into
pytest-dev:mainfrom
megacodes24:move-collection-error-check
Open

megacodes24 wants to merge 1 commit into
pytest-dev:mainfrom
megacodes24:move-collection-error-check

Conversation

@megacodes24

@megacodes24 megacodes24 commented Nov 13, 2026 •

Copy link
Copy Markdown

Closes #15028.

The check that stops the session after collection errors lived in the default pytest_runtestloop. Since that hook is firstresult, a plugin that implements its own pytest_runtestloop never reached the check, and tests ran even though collection failed. As suggested by @bluetech in the issue, this moves the check into the default pytest_collection.

This picks up #15061 by @gyanu2507, which the author closed and invited others to continue. Compared to that PR:

  • In the pytest_collection docstring, Interrupted is written as a literal instead of :class:~pytest.Interrupted. Interrupted is not exported from the pytest namespace, so I believe that reference is what failed the Read the Docs build there (the docs build is nitpicky).
  • Added a second test checking that with --continue-on-collection-errors, a plugin's pytest_runtestloop still runs.

Changes:

  • src/_pytest/main.py: moved the testsfailed check from pytest_runtestloop to pytest_collection.
  • src/_pytest/hookspec.py: updated the pytest_collection and pytest_runtestloop docstrings.
  • testing/test_collection.py: two new tests.
  • changelog/15028.breaking.rst: breaking change entry, since the current behavior is documented.

How I tested (Windows, Python 3.12):

  • Reproduced the issue with a small project whose conftest.py replaces pytest_runtestloop and a test file that fails to import. Before the change: 1 passed, 1 error. After: Interrupted: 1 error during collection.

  • With the original main.py, the first new test fails (INTERNAL_ERROR instead of INTERRUPTED), and it passes with the change.

  • testing/test_collection.py: 109 passed. test_main.py, test_terminal.py, acceptance_test.py pass except test_pydoc, which also fails on main on my machine (UnicodeDecodeError, a Windows encoding issue unrelated to this change).

  • pre-commit passes on the changed files.

  • Include new tests or update existing tests when applicable.

  • Allow maintainers to push and squash when merging my commits.

  • Add text like closes #XYZW to the PR description and/or commits.

  • If AI agents were used, they are credited in Co-authored-by commit trailers.

  • Create a new changelog file in the changelog directory.

  • Add yourself to AUTHORS in alphabetical order.

@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Nov 13, 2026

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.

Collection-error abort check lives in pytest_runtestloop instead of pytest_collection

1 participant