@@ -87,54 +87,20 @@ def reporter(self, func):
8787 :return: Wrapped function.
8888 """
8989
90- exceptions_to_catch = tuple (self ._exceptions_to_catch ) if self ._exceptions_to_catch else None
91- exceptions_to_ignore = tuple (self ._exceptions_to_ignore ) if self ._exceptions_to_ignore else None
92-
93- if exceptions_to_catch and exceptions_to_ignore :
94- @_wraps (func )
95- def wrap (* args , ** kwargs ):
96- try :
97- return func (* args , ** kwargs )
98- except BaseException as e :
99- if isinstance (e , exceptions_to_catch ) and not isinstance (e , exceptions_to_ignore ):
100- self ._reporter_function (e )
101- if self .raise_after_report :
102- raise e
103- else :
104- raise e
105- elif self ._exceptions_to_catch :
106- @_wraps (func )
107- def wrap (* args , ** kwargs ):
108- try :
109- return func (* args , ** kwargs )
110- except BaseException as e :
111- if isinstance (e , exceptions_to_catch ):
112- self ._reporter_function (e )
113- if self .raise_after_report :
114- raise e
115- else :
116- raise e
117- elif self ._exceptions_to_ignore :
118- @_wraps (func )
119- def wrap (* args , ** kwargs ):
120- try :
121- return func (* args , ** kwargs )
122- except BaseException as e :
123- if not isinstance (e , exceptions_to_ignore ):
124- self ._reporter_function (e )
125- if self .raise_after_report :
126- raise e
127- else :
128- raise e
129- else :
130- @_wraps (func )
131- def wrap (* args , ** kwargs ):
132- try :
133- return func (* args , ** kwargs )
134- except BaseException as e :
90+ exceptions_to_catch = tuple (self ._exceptions_to_catch ) if self ._exceptions_to_catch else BaseException
91+ exceptions_to_ignore = tuple (self ._exceptions_to_ignore ) if self ._exceptions_to_ignore else tuple ()
92+
93+ @_wraps (func )
94+ def wrap (* args , ** kwargs ):
95+ try :
96+ return func (* args , ** kwargs )
97+ except BaseException as e :
98+ if isinstance (e , exceptions_to_catch ) and not isinstance (e , exceptions_to_ignore ):
13599 self ._reporter_function (e )
136100 if self .raise_after_report :
137101 raise e
102+ else :
103+ raise e
138104
139105 return wrap
140106
@@ -144,19 +110,29 @@ def catch(self, exception: BaseException):
144110
145111 :param exception: Exception to catch.
146112 """
113+ if not isinstance (exception , BaseException ):
114+ raise TypeError ('`exception` must be an instance of BaseException' )
147115 if self ._exceptions_to_catch is None :
148116 self ._exceptions_to_catch = set ()
149- self ._exceptions_to_catch .add (exception )
117+ if exception not in self ._exceptions_to_catch :
118+ self ._exceptions_to_catch .add (exception )
119+ else :
120+ raise ValueError ('exception is already in the list of exceptions to catch' )
150121
151122 def ignore (self , exception : BaseException ):
152123 """
153124 Add an exception to the list of exceptions to ignore.
154125
155126 :param exception: Exception to ignore.
156127 """
128+ if not isinstance (exception , BaseException ):
129+ raise TypeError ('`exception` must be an instance of BaseException' )
157130 if self ._exceptions_to_ignore is None :
158131 self ._exceptions_to_ignore = set ()
159- self ._exceptions_to_ignore .add (exception )
132+ if exception not in self ._exceptions_to_ignore :
133+ self ._exceptions_to_ignore .add (exception )
134+ else :
135+ raise ValueError ('exception is already in the list of exceptions to ignore' )
160136
161137
162138class ConsoleReporter (Reporter ):
0 commit comments