Fix LOG_FILE_PATH initialization under pytest#133
Open
Raihan93-coder wants to merge 1 commit into
Open
Conversation
|
INFO: No unicode characters found in PR's commits (source) |
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: _LiveLoggingNullHandler object has no attribute baseFilename
The 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 🤓
A small error has happened so I am opening this new PR instead of #132 😞