@@ -314,6 +314,32 @@ def _comment_line(line):
314314 else :
315315 return '#'
316316
317+ def _strip_exception_details (msg ):
318+ # Support for IGNORE_EXCEPTION_DETAIL.
319+ # Get rid of everything except the exception name; in particular, drop
320+ # the possibly dotted module path (if any) and the exception message (if
321+ # any). We assume that a colon is never part of a dotted name, or of an
322+ # exception name.
323+ # E.g., given
324+ # "foo.bar.MyError: la di da"
325+ # return "MyError"
326+ # Or for "abc.def" or "abc.def:\n" return "def".
327+
328+ start , end = 0 , len (msg )
329+ # The exception name must appear on the first line.
330+ i = msg .find ("\n " )
331+ if i >= 0 :
332+ end = i
333+ # retain up to the first colon (if any)
334+ i = msg .find (':' , 0 , end )
335+ if i >= 0 :
336+ end = i
337+ # retain just the exception name
338+ i = msg .rfind ('.' , 0 , end )
339+ if i >= 0 :
340+ start = i + 1
341+ return msg [start : end ]
342+
317343class _OutputRedirectingPdb (pdb .Pdb ):
318344 """
319345 A specialized version of the python debugger that redirects stdout
@@ -1320,10 +1346,9 @@ def __run(self, test, compileflags, out):
13201346
13211347 # Another chance if they didn't care about the detail.
13221348 elif self .optionflags & IGNORE_EXCEPTION_DETAIL :
1323- m1 = re .match (r'(?:[^:]*\.)?([^:]*:)' , example .exc_msg )
1324- m2 = re .match (r'(?:[^:]*\.)?([^:]*:)' , exc_msg )
1325- if m1 and m2 and check (m1 .group (1 ), m2 .group (1 ),
1326- self .optionflags ):
1349+ if check (_strip_exception_details (example .exc_msg ),
1350+ _strip_exception_details (exc_msg ),
1351+ self .optionflags ):
13271352 outcome = SUCCESS
13281353
13291354 # Report the outcome.
0 commit comments