File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 1
1
"""Fixtures for all tests."""
2
2
3
+ import logging
3
4
from unittest .mock import AsyncMock , Mock
4
5
5
6
import pytest
@@ -305,3 +306,31 @@ def __getattr__(self, key):
305
306
assert isinstance (device , quirk )
306
307
307
308
return _check
309
+
310
+
311
+ class FailOnBadFormattingHandler (logging .Handler ):
312
+ """Logging handler that fails the test if a log message cannot be formatted."""
313
+
314
+ def emit (self , record ):
315
+ """No-op record emitter."""
316
+ try :
317
+ record .msg % record .args
318
+ except Exception as e : # noqa: BLE001
319
+ pytest .fail (
320
+ f"Failed to format log message { record .msg !r} with { record .args !r} : { e } "
321
+ )
322
+
323
+
324
+ @pytest .fixture (autouse = True )
325
+ def raise_on_bad_log_formatting ():
326
+ """Fixture to ensure that all log messages can be formatted correctly."""
327
+ handler = FailOnBadFormattingHandler ()
328
+
329
+ root = logging .getLogger ()
330
+ root .addHandler (handler )
331
+ root .setLevel (logging .DEBUG )
332
+
333
+ try :
334
+ yield
335
+ finally :
336
+ root .removeHandler (handler )
Original file line number Diff line number Diff line change @@ -133,8 +133,7 @@ def _find_zcl_cluster(
133
133
return super ()._find_zcl_cluster (hdr , packet )
134
134
except KeyError :
135
135
_LOGGER .debug (
136
- "Packet is coming in the wrong direction for cluster %s on endpoint %s,"
137
- " swapping direction and trying again"
136
+ "Packet is coming in the wrong direction, swapping direction and trying again" ,
138
137
)
139
138
140
139
return super ()._find_zcl_cluster (
You can’t perform that action at this time.
0 commit comments