Fixing log errors at the end of tests#7340
Merged
thabofletcher merged 2 commits intomainfrom Feb 7, 2026
Merged
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
Contributor
Greptile OverviewGreptile SummaryThis PR fixes noisy logging errors that appeared at the end of test runs when asyncio emitted late log messages after pytest closed
Confidence Score: 5/5
Important Files Changed
|
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.
Description Of Changes
During test teardown (and interpreter shutdown), Python's asyncio emits a late
DEBUG-level log message ("Using selector: EpollSelector") via the standardloggingmodule. Because theInterceptHandlerroutes all standard library logs through Loguru, this message reaches Loguru's stdout sink after pytest has already closedsys.stdout. Loguru'scatch=Truecatches the resultingValueErrorbut prints a noisy diagnostic block at the end of every test run:This is harmless (no logs are lost, no tests are affected) but it's confusing and noisy.
The fix replaces the raw
sys.stdoutfile object with a callable sink function (_safe_stdout_sink) that wrapssys.stdout.write()in atry/except ValueError. This is idiomatic for Loguru — callable sinks are a first-class feature and the codebase already uses one for theRedisSink. Callable sinks bypass Loguru'sSimpleSinkwrapper entirely, so the error is caught by our function before Loguru's error reporting ever sees it.Code Changes
_safe_stdout_sinkcallable sink function that writes tosys.stdoutand silently dropsValueErrorfrom closed file descriptorssetup()to use_safe_stdout_sinkas the default sink instead ofsys.stdoutdirectlySteps to Confirm
nox -s pytestorpytest --no-covinside the container)--- Logging error in Loguru Handler #5 ---diagnostic no longer appears at the end of the test outputPre-Merge Checklist
CHANGELOG.mdupdatedmaindowngrade()migration is correct and works