Skip to content

fix: allow logs to propagate upstream for caplog testing #1374

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

Merged
merged 2 commits into from
Mar 10, 2025

Conversation

ohmayr
Copy link
Contributor

@ohmayr ohmayr commented Mar 6, 2025

When tests are run in parallel and a base logger is not configured, then the log propagation from the base logger (i.e. a google named logger) to the root logger is disabled (this happens during client construction):

logger = logging.getLogger("google")
logger.propagate = False

Given that the above is a global config, any of the tests that use the caplog fixture start to fail once the propagation of logs to the root logger is disabled. This means that nothing is captured for a logger (by caplog) if it does not propagate to the root logger. See pytest-dev/pytest#3697.

As a workaround, we can allow propagation of logs to the root logger for a test run and then revert it to the original value once the test completes.

Fixes: b/388826364

Note: By default, log propagation to the root logger is disabled. This behaviour is captured in the README.

@ohmayr ohmayr requested review from a team as code owners March 6, 2025 19:39
@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Mar 6, 2025
@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/python-pubsub API. label Mar 6, 2025
@parthea parthea removed their assignment Mar 7, 2025
@mukund-ananthu mukund-ananthu enabled auto-merge (squash) March 10, 2025 22:13
@mukund-ananthu mukund-ananthu merged commit fa39b0e into main Mar 10, 2025
27 checks passed
@mukund-ananthu mukund-ananthu deleted the modify-google-logger branch March 10, 2025 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/python-pubsub API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants