Skip to content

Fix pytest logging#132

Closed
Raihan93-coder wants to merge 5 commits into
BusKill:devfrom
Raihan93-coder:fix-pytest-logging
Closed

Fix pytest logging#132
Raihan93-coder wants to merge 5 commits into
BusKill:devfrom
Raihan93-coder:fix-pytest-logging

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 🤓

@github-actions

Copy link
Copy Markdown

INFO: No unicode characters found in PR's commits

(source)

@Raihan93-coder

Copy link
Copy Markdown
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.

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