fix(testing): Prevent logging setup when --help is passed#2923
Merged
gaborbernat merged 1 commit intopypa:mainfrom Aug 1, 2025
Merged
fix(testing): Prevent logging setup when --help is passed#2923gaborbernat merged 1 commit intopypa:mainfrom
gaborbernat merged 1 commit intopypa:mainfrom
Conversation
This commit fixes a flaky test, `test_zipapp_help`, which would fail intermittently due to unexpected output on stderr. The root cause of the flakiness was that `virtualenv` would set up its logging framework based on verbosity flags (`-v`, `-vv`, etc.) *before* processing the `--help` flag. This could lead to log messages being generated during the initialization process, which, under certain conditions, would be written to stderr, causing the test to fail. The fix is to check for the presence of `-h` or `--help` in the command-line arguments within the `_do_report_setup` function. If either of these flags is found, the logging setup is skipped entirely. This is safe because the application will exit immediately after printing the help message, so no logging is required. This change ensures that no logging output is generated when you request help, which resolves the flaky test and makes the application's behavior more predictable. Following the fix, the `@pytest.mark.flaky` annotation has been removed from the `test_zipapp_help` test, as it is no longer needed. Signed-off-by: Emre Şafak <3928300+esafak@users.noreply.github.com>
gaborbernat
approved these changes
Aug 1, 2025
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.
This commit fixes a flaky test,
test_zipapp_help, which would fail intermittently due to unexpected output on stderr.The root cause of the flakiness was that
virtualenvwould set up its logging framework based on verbosity flags (-v,-vv, etc.) before processing the--helpflag. This could lead to log messages being generated during the initialization process, which, under certain conditions, would be written to stderr, causing the test to fail.The fix is to check for the presence of
-hor--helpin the command-line arguments within the_do_report_setupfunction. If either of these flags is found, the logging setup is skipped entirely. This is safe because the application will exit immediately after printing the help message, so no logging is required.This change ensures that no logging output is generated when you request help, which resolves the flaky test and makes the application's behavior more predictable.
Following the fix, the
@pytest.mark.flakyannotation has been removed from thetest_zipapp_helptest, as it is no longer needed.I am not sure how to name the news fragment when there is no corresponding Issue so I copied an example in commit history.
tox -e fix)docs/changelogfolder