Skip to content

Commit

Permalink
Some logging internals rely on the boolean value of a Handler
Browse files Browse the repository at this point in the history
They should use identity comparison with None, but they do not...
  • Loading branch information
cjw296 committed Jun 7, 2024
1 parent b5c28ab commit 25a3607
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions testfixtures/logcapture.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def atexit(cls):
'%s' % ('\n'.join((str(i.names) for i in cls.instances)))
)

def __bool__(self) -> bool:
# Some logging internals check boolean rather than identity for handlers :-(r
return True

def __len__(self):
return len(self.records)

Expand Down
4 changes: 4 additions & 0 deletions testfixtures/tests/test_logcapture.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ def test_len_and_getitem(self):
compare(len(log), expected=1)
compare(log[0], expected=('foo', 'INFO', 'a log message'))

def test_truthiness_when_empty(self):
handler = LogCapture(install=False)
assert handler
assert bool(handler)
class TestCheckPresent:

def test_order_matters_ok(self):
Expand Down

0 comments on commit 25a3607

Please sign in to comment.