Repository navigation
Move collection error abort from pytest_runtestloop to pytest_collection - #15384
Open
megacodes24 wants to merge 1 commit into
Open
megacodes24 wants to merge 1 commit into
megacodes24 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #15028.
The check that stops the session after collection errors lived in the default
pytest_runtestloop. Since that hook isfirstresult, a plugin that implements its ownpytest_runtestloopnever reached the check, and tests ran even though collection failed. As suggested by @bluetech in the issue, this moves the check into the defaultpytest_collection.This picks up #15061 by @gyanu2507, which the author closed and invited others to continue. Compared to that PR:
pytest_collectiondocstring,Interruptedis written as a literal instead of:class:~pytest.Interrupted.Interruptedis not exported from thepytestnamespace, so I believe that reference is what failed the Read the Docs build there (the docs build is nitpicky).--continue-on-collection-errors, a plugin'spytest_runtestloopstill runs.Changes:
src/_pytest/main.py: moved thetestsfailedcheck frompytest_runtestlooptopytest_collection.src/_pytest/hookspec.py: updated thepytest_collectionandpytest_runtestloopdocstrings.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.pyreplacespytest_runtestloopand 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_ERRORinstead ofINTERRUPTED), and it passes with the change.testing/test_collection.py: 109 passed.test_main.py,test_terminal.py,acceptance_test.pypass excepttest_pydoc, which also fails onmainon 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 #XYZWto the PR description and/or commits.If AI agents were used, they are credited in
Co-authored-bycommit trailers.Create a new changelog file in the
changelogdirectory.Add yourself to
AUTHORSin alphabetical order.