Add --max-warnings option to fail test runs#14372
Open
miketheman wants to merge 1 commit intopytest-dev:mainfrom
Open
Add --max-warnings option to fail test runs#14372miketheman wants to merge 1 commit intopytest-dev:mainfrom
--max-warnings option to fail test runs#14372miketheman wants to merge 1 commit intopytest-dev:mainfrom
Conversation
Allow users to set a maximum number of allowed warnings via --max-warnings CLI option or max_warnings config option. When the warning count exceeds the threshold and all tests pass, pytest exits with a new WARNINGS_ERROR exit code (6). This supports gradually ratcheting down warnings in a codebase without converting them all to errors. Based on the pytest-max-warnings plugin by @miketheman, with improvements: a dedicated ExitCode instead of an arbitrary exit code, and INI config support. Closes pytest-dev#14371 Signed-off-by: Mike Fiedler <miketheman@gmail.com>
miketheman
commented
Apr 8, 2026
| :Exit code 3: Internal error happened while executing tests | ||
| :Exit code 4: pytest command line usage error | ||
| :Exit code 5: No tests were collected | ||
| :Exit code 6: Maximum number of warnings exceeded (see :option:`--max-warnings`) |
Author
There was a problem hiding this comment.
I debated on whether to add an explicit code, and since this doesn't match ExitCode 1, I chose to add another.
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.
Allow users to set a maximum number of allowed warnings via --max-warnings CLI option or max_warnings config option. When the warning count exceeds the threshold and all tests pass, pytest exits with a new WARNINGS_ERROR exit code (6). This supports gradually ratcheting down warnings in a codebase without converting them all to errors.
Based on the pytest-max-warnings plugin by @miketheman, with improvements: a dedicated ExitCode instead of an arbitrary exit code, and INI config support.
Closes #14371