Introduce StdoutCaptureManager to isolate stdout from logging logs#54065
Merged
potiuk merged 4 commits intoapache:mainfrom Aug 7, 2025
Merged
Introduce StdoutCaptureManager to isolate stdout from logging logs#54065potiuk merged 4 commits intoapache:mainfrom
StdoutCaptureManager to isolate stdout from logging logs#54065potiuk merged 4 commits intoapache:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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
potiuk
approved these changes
Aug 7, 2025
Member
|
Let's hope there will be no more flakiness :) |
18 tasks
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.
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.