Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 08bba95

Browse files
committed
doctest doesn't handle intentional SyntaxError exceptions gracefully,
because it picks up the first line of traceback.format_exception_only() instead of the last line. Pick up the last line instead!
1 parent ee30927 commit 08bba95

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

Lib/doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def _run_examples_inner(out, fakeout, examples, globs, verbose, name):
501501
# the traceback isn't necessary.
502502
want = want.split('\n')[-2] + '\n'
503503
exc_type, exc_val, exc_tb = sys.exc_info()
504-
got = traceback.format_exception_only(exc_type, exc_val)[0]
504+
got = traceback.format_exception_only(exc_type, exc_val)[-1]
505505
state = OK
506506
else:
507507
# unexpected exception

0 commit comments

Comments
 (0)