Skip to content

Fix LOG_FILE_PATH initialization under pytest#133

Open
Raihan93-coder wants to merge 1 commit into
BusKill:devfrom
Raihan93-coder:fix-pytest-logging-clean
Open

Fix LOG_FILE_PATH initialization under pytest#133
Raihan93-coder wants to merge 1 commit into
BusKill:devfrom
Raihan93-coder:fix-pytest-logging-clean

Conversation

@Raihan93-coder

Copy link
Copy Markdown

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 😞

@github-actions

Copy link
Copy Markdown

INFO: No unicode characters found in PR's commits

(source)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant