diff options
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r-- | Lib/doctest.py | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index 43f21b2..01f7cb3 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -1281,15 +1281,14 @@ class DocTestRunner: # A regular expression for handling `want` strings that contain # expected exceptions. It divides `want` into three pieces: - # - the pre-exception output (`want`) # - the traceback header line (`hdr`) + # - the traceback stack (`stack`) # - the exception message (`msg`), as generated by # traceback.format_exception_only() # `msg` may have multiple lines. We assume/require that the # exception message is the first non-indented line starting with a word # character following the traceback header line. _EXCEPTION_RE = re.compile(r""" - (?P<want> .*?) # suck up everything until traceback header # Grab the traceback header. Different versions of Python have # said different things on the first traceback line. ^(?P<hdr> Traceback\ \( @@ -1297,9 +1296,9 @@ class DocTestRunner: | innermost\ last ) \) : ) - \s* $ # toss trailing whitespace on traceback header - .*? # don't blink: absorb stuff until a line *starts* with \w - ^ (?P<msg> \w+ .*) + \s* $ # toss trailing whitespace on the header. + (?P<stack> .*?) # don't blink: absorb stuff until... + ^ (?P<msg> \w+ .*) # a line *starts* with alphanum. """, re.VERBOSE | re.MULTILINE | re.DOTALL) def __run(self, test, compileflags, out): @@ -1374,13 +1373,10 @@ class DocTestRunner: exc_info) failures += 1 else: - e_want, e_msg = m.group('want', 'msg') - # The test passes iff the pre-exception output and - # the exception description match the values given - # in `want`. - if (self._checker.check_output(e_want, got, - self.optionflags) and - self._checker.check_output(e_msg, exc_msg, + # The test passes iff the expected exception + # message (`m.group('msg')`) matches the actual + # exception message (`exc_msg`). + if (self._checker.check_output(m.group('msg'), exc_msg, self.optionflags)): self.report_success(out, test, example, got + _exception_traceback(exc_info)) |