Fix pytest logging#132
Closed
Raihan93-coder wants to merge 5 commits into
Closed
Conversation
|
INFO: No unicode characters found in PR's commits (source) |
Author
|
Closing this PR because it unintentionally includes commits from a previous branch. I'll open a new PR containing only the pytest logging fix. |
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.
Pytest logging
This solves the issue raised in #131.
Problem
When BusKill is instantiated under pytest,
logger.root.handlers[0]may be a_LiveLoggingNullHandler. Unlike a normal FileHandler, this object does not provide a baseFilename attribute, causing:AttributeError:
_LiveLoggingNullHandlerobject has no attributebaseFilenameThe previous fix introduced in #121 prevented an IndexError when no handlers were present, but it did not handle logging handlers that lack a baseFilename attribute.
Solution
Use getattr() when retrieving baseFilename and handle the case where no handlers are present. ( Solution given by @prashanth-kaki )
This prevents both:
IndexError when logger.root.handlers is empty. ( In the PR #121 )
AttributeError when the active logging handler does not provide baseFilename. ( Implemented in this PR )
Testing
Reproduced on:
Parrot Security 6.4 (Debian 12 based OS)
Python 3.13.9
pytest 9.1.0
Verified that BusKill() can now be instantiated successfully under pytest without raising an exception 🤓