@@ -318,6 +318,32 @@ def _comment_line(line):
318318 else :
319319 return '#'
320320
321+ def _strip_exception_details (msg ):
322+ # Support for IGNORE_EXCEPTION_DETAIL.
323+ # Get rid of everything except the exception name; in particular, drop
324+ # the possibly dotted module path (if any) and the exception message (if
325+ # any). We assume that a colon is never part of a dotted name, or of an
326+ # exception name.
327+ # E.g., given
328+ # "foo.bar.MyError: la di da"
329+ # return "MyError"
330+ # Or for "abc.def" or "abc.def:\n" return "def".
331+
332+ start , end = 0 , len (msg )
333+ # The exception name must appear on the first line.
334+ i = msg .find ("\n " )
335+ if i >= 0 :
336+ end = i
337+ # retain up to the first colon (if any)
338+ i = msg .find (':' , 0 , end )
339+ if i >= 0 :
340+ end = i
341+ # retain just the exception name
342+ i = msg .rfind ('.' , 0 , end )
343+ if i >= 0 :
344+ start = i + 1
345+ return msg [start : end ]
346+
321347class _OutputRedirectingPdb (pdb .Pdb ):
322348 """
323349 A specialized version of the python debugger that redirects stdout
@@ -1325,10 +1351,9 @@ def __run(self, test, compileflags, out):
13251351
13261352 # Another chance if they didn't care about the detail.
13271353 elif self .optionflags & IGNORE_EXCEPTION_DETAIL :
1328- m1 = re .match (r'(?:[^:]*\.)?([^:]*:)' , example .exc_msg )
1329- m2 = re .match (r'(?:[^:]*\.)?([^:]*:)' , exc_msg )
1330- if m1 and m2 and check (m1 .group (1 ), m2 .group (1 ),
1331- self .optionflags ):
1354+ if check (_strip_exception_details (example .exc_msg ),
1355+ _strip_exception_details (exc_msg ),
1356+ self .optionflags ):
13321357 outcome = SUCCESS
13331358
13341359 # Report the outcome.
0 commit comments