Skip to content

fix: guard LOG_FILE_PATH against handlers without baseFilename (fixes #131)#134

Open
charlesaurav13 wants to merge 1 commit into
BusKill:masterfrom
charlesaurav13:fix/131-pytest-log-handler-compat
Open

fix: guard LOG_FILE_PATH against handlers without baseFilename (fixes #131)#134
charlesaurav13 wants to merge 1 commit into
BusKill:masterfrom
charlesaurav13:fix/131-pytest-log-handler-compat

Conversation

@charlesaurav13

Copy link
Copy Markdown

Summary

  • BusKill.__init__ hard-coded logger.root.handlers[0].baseFilename on line 227
  • pytest replaces the root handler with _LiveLoggingNullHandler, which has no baseFilename attribute, so every test that instantiates BusKill() crashed with AttributeError
  • Fixed by using getattr(handler, 'baseFilename', None) and also guarding against an empty handlers list

Changes

src/packages/buskill/__init__.py line 227:

# before
self.LOG_FILE_PATH = logger.root.handlers[0].baseFilename

# after
handler = logger.root.handlers[0] if logger.root.handlers else None
self.LOG_FILE_PATH = getattr(handler, 'baseFilename', None)

Test plan

  • Instantiate BusKill() inside a pytest test — no longer raises AttributeError
  • Normal runtime behaviour unchanged: LOG_FILE_PATH still resolves to the log file path when a FileHandler is configured

Closes #131

…name

Fixes BusKill#131. pytest replaces the root log handler with
_LiveLoggingNullHandler, which has no baseFilename attribute. The bare
attribute access on line 227 raised AttributeError on every test run,
making BusKill completely untestable under pytest.

Use getattr with a None default so BusKill can be instantiated safely
in any logging environment, including pytest's.

Signed-off-by: charlesaurav13 <sauravp1236@gmail.com>
@github-actions

Copy link
Copy Markdown

INFO: No unicode characters found in PR's commits

(source)

@maltfield

Copy link
Copy Markdown
Member

Thanks for the PR :)

Please note that this repo does not accept contributions that use AI

Can you please tell us if you wrote this code, comments, and PR contents entirely by yourself? Or if you used AI for any part of it?

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.

BusKill.__init__ incompatible with pytest's log handler (_LiveLoggingNullHandler has no baseFilename)

2 participants