#15028·pytest

Collection-error abort check lives in `pytest_runtestloop` instead of `pytest_collection`

Author: SemTiOneCreated Sep 15, 2026Updated Sep 16, 2026

What's the problem this feature will solve?

The collection-error abort check lives in the default pytest_runtestloop (src/_pytest/main.py), so the runtest phase inspects leftovers from collection instead of collection guarding itself.

Describe the solution you'd like

Move the testsfailed check into the default pytest_collection, keeping the exception and exit code. Both hooks are firstresult hooks, so audit which implementations bypass the check before moving it.

Alternative Solutions

Leave as is (behavior is correct).

Additional context

Deferred from #15012 (https://github.com/pytest-dev/pytest/pull/15012#discussion_r4005164212). This can be closed as wontfix if the compatibility impact outweighs the benefit.