fix(testing): Prevent logging setup when --help is passed #2923
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
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 thetest_zipapp_help
test, 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/changelog
folder