-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Introduce StdoutCaptureManager to isolate stdout from logging logs
#54065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a StdoutCaptureManager context manager to isolate stdout capture from logging output in CLI tests, preventing test failures caused by debug logging interference. The context manager filters out log messages that would otherwise contaminate stdout assertions in CLI command tests.
- Adds a new
StdoutCaptureManagerclass that removes stdout logging handlers during stdout capture - Replaces
unittest.mockusage with pytest'smockerfixture across multiple test files - Updates CLI test files to use the new
stdout_capturefixture instead of directredirect_stdoutcalls
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| airflow-core/tests/unit/cli/conftest.py | Adds the StdoutCaptureManager class and stdout_capture pytest fixture |
| airflow-core/tests/unit/cli/commands/test_*.py | Updates CLI command tests to use new stdout capture fixture and pytest mocker |
85aa959 to
b2607fc
Compare
+ Replace some uses of unittest.mock with pytest's mocker fixture
`test_cli_connections_import_should_load_connections`: the test expects to see an error about "new3" but only sees "Imported connection new1". The test setup only creates "new0" and "new1", so "new3" doesn't exist. The test seems to have incorrect logic or expectations.
(theory: the test is looking at stdout, and if a warning is present there, it doesn't find the text it expects on the right line)
b2607fc to
da8bbf2
Compare
|
Let's hope there will be no more flakiness :) |
As part of adding some debug logging in another PR, a lot of tests failed because they appear to capture all the logs then compare them (for equality) to some expected output.
The initial plan was to use
caplogto isolate the logger of interest, then use membership/intersection for assertions instead of equality. However, upon closer inspection of the failures, it quickly became apparent that their majority was related to CLI tests, which assert againststdoutand not some particular logger. So a different approach was taken, which is to create a context manager fixture that filters out messages originating from the logging module.In addition, some uses of
unittest.mockwere replaced with pytest'smockerfixture.^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in airflow-core/newsfragments.