Introduce ExitCode.COLLECTION_ERROR for collection errors - #15012
Introduce ExitCode.COLLECTION_ERROR for collection errors#15012SemTiOne wants to merge 5 commits into
ExitCode.COLLECTION_ERROR for collection errors#15012Conversation
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
RonnyPfannschmidt
left a comment
There was a problem hiding this comment.
I like it
We may need to assess if this is breaking for some people
|
ci fixed needed |
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
ExitCode.COLLECTION_ERROR for collection errorsExitCode.COLLECTION_ERROR for collection errors
Pierre-Sassoulas
left a comment
There was a problem hiding this comment.
LGTM. More tests changed than code is a good sign.
|
please investigate what triggered the rtd failure |
|
GTG. |
bluetech
left a comment
There was a problem hiding this comment.
LGTM. I left a few comments but nothing to change really.
| @@ -399,7 +401,7 @@ def pytest_collection(session: Session) -> None: | |||
|
|
|||
| def pytest_runtestloop(session: Session) -> bool: | |||
| if session.testsfailed and not session.config.option.continue_on_collection_errors: | |||
There was a problem hiding this comment.
(Preexisting) I'm curious why this check happens in pytest_runtestloop instead of pytest_collection. To me it makes more sense as part of the collection phase, instead of runtest phase needing to check for "leftovers" from collection.
| Subclasses ``Interrupted`` for compatibility; ``wrap_session`` maps it | ||
| to ``ExitCode.COLLECTION_ERROR``. |
There was a problem hiding this comment.
IMO a lower level shouldn't refer to what a higher level does with it. It can easily become outdated.
| Subclasses ``Interrupted`` for compatibility; ``wrap_session`` maps it | |
| to ``ExitCode.COLLECTION_ERROR``. | |
| Subclasses ``Interrupted`` for compatibility. |
| "", | ||
| "test_collect_error_with_fulltrace.py:1: AssertionError", | ||
| "*! Interrupted: 1 error during collection !*", | ||
| "*! CollectionInterrupted: 1 error during collection !*", |
There was a problem hiding this comment.
This looks a bit ugly to me, in the sense that as a user it would look to me like pytest's implementation leaks into the user interface. Interrupted is less jarring because it's a proper word. Though I guess KeyboardInterrupt is the same. So it's fine.
An alternative is to avoid a separate CollectionInterrupted exception and use a parameter to Interrupted instead. But I figure you intentionally separated the two, since "interrupted" is really not a good fit for collection errors, but have to do it for backward compat.
| exitstatus: int | ExitCode = ExitCode.INTERRUPTED | ||
| if isinstance(excinfo.value, CollectionInterrupted): | ||
| exitstatus = ExitCode.COLLECTION_ERROR | ||
| if isinstance(excinfo.value, exit.Exception): |
There was a problem hiding this comment.
| if isinstance(excinfo.value, exit.Exception): | |
| elif isinstance(excinfo.value, exit.Exception): |
| if session.shouldfail: | ||
| self.write_sep("!", str(session.shouldfail), red=True) | ||
| if exitstatus == ExitCode.INTERRUPTED: | ||
| if exitstatus in (ExitCode.INTERRUPTED, ExitCode.COLLECTION_ERROR): |
There was a problem hiding this comment.
(Preexisting) I wonder why we have _report_keyboardinterrupt both in pytest_sessionfinish and in pytest_unconfigure. Probably there's a good reason, I wish there was a code comment for it.
Closes #4603
Previously collection errors exited 2, they now exit 7 (
ExitCode.COLLECTION_ERROR).closes #XYZWto the PR description and/or commits (whereXYZWis the issue number). See the github docs for more information.Co-authored-bycommit trailers.changelogdirectory, with a name like<ISSUE NUMBER>.<TYPE>.rst. See changelog/README.rst for details.AUTHORSin alphabetical order.