@@ -477,6 +477,29 @@ def func(test_arg1, test_arg2):
477477 ),
478478 ))
479479
480+ def test_exceptions_blacklist (self , logger ):
481+ new_logger = mock .Mock (spec = logging .Logger , name = 'logger' )
482+ log = mock .Mock (name = 'log' )
483+ new_logger .attach_mock (log , 'log' )
484+
485+ @logwrap .logwrap (log = new_logger , blacklisted_exceptions = [TypeError ])
486+ def func ():
487+ raise TypeError ('Blacklisted' )
488+
489+ with self .assertRaises (TypeError ):
490+ func ()
491+
492+ self .assertEqual (len (logger .mock_calls ), 0 )
493+ self .assertEqual (
494+ log .mock_calls ,
495+ [
496+ mock .call (
497+ level = logging .DEBUG ,
498+ msg = "Calling: \n 'func'()"
499+ ),
500+ ]
501+ )
502+
480503
481504@mock .patch ('logwrap._log_wrap_shared.logger' , autospec = True )
482505@unittest .skipUnless (
@@ -647,3 +670,42 @@ def func():
647670 msg = "Done: 'func' with result:\n None"
648671 )
649672 ))
673+
674+ def test_exceptions_blacklist (self , logger ):
675+ new_logger = mock .Mock (spec = logging .Logger , name = 'logger' )
676+ log = mock .Mock (name = 'log' )
677+ new_logger .attach_mock (log , 'log' )
678+
679+ namespace = {
680+ 'logwrap' : logwrap ,
681+ 'loop' : self .loop ,
682+ 'new_logger' : new_logger ,
683+ 'assertRaises' : self .assertRaises
684+ }
685+
686+ exec ("""
687+ import asyncio
688+
689+ @logwrap.async_logwrap(log=new_logger, blacklisted_exceptions=[TypeError])
690+ @asyncio.coroutine
691+ def func():
692+ raise TypeError('Blacklisted')
693+
694+ with assertRaises(TypeError):
695+ loop.run_until_complete(func())
696+ """ ,
697+ namespace
698+ )
699+ # While we're not expanding result coroutine object from namespace,
700+ # do not check execution result
701+
702+ self .assertEqual (len (logger .mock_calls ), 0 )
703+ self .assertEqual (
704+ log .mock_calls ,
705+ [
706+ mock .call (
707+ level = logging .DEBUG ,
708+ msg = "Awaiting: \n 'func'()"
709+ ),
710+ ]
711+ )
0 commit comments