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 11"""Fixtures for all tests.""" 
22
3+ import  logging 
34from  unittest .mock  import  AsyncMock , Mock 
45
56import  pytest 
@@ -305,3 +306,31 @@ def __getattr__(self, key):
305306        assert  isinstance (device , quirk )
306307
307308    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(
133133            return  super ()._find_zcl_cluster (hdr , packet )
134134        except  KeyError :
135135            _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" ,
138137            )
139138
140139            return  super ()._find_zcl_cluster (
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments