diff -r 725131a5f6cf Lib/doctest.py --- a/Lib/doctest.py Sat Jul 04 22:52:33 2015 -0500 +++ b/Lib/doctest.py Tue Jul 28 21:23:09 2015 -0400 @@ -1680,7 +1680,6 @@ else: assert 0, 'Bad diff option' # Remove trailing whitespace on diff output. - diff = [line.rstrip() + '\n' for line in diff] return 'Differences (%s):\n' % kind + _indent(''.join(diff)) # If we're not using diff, then simply list the expected diff -r 725131a5f6cf Lib/test/test_doctest.py --- a/Lib/test/test_doctest.py Sat Jul 04 22:52:33 2015 -0500 +++ b/Lib/test/test_doctest.py Tue Jul 28 21:23:09 2015 -0400 @@ -1392,6 +1392,36 @@ g TestResults(failed=1, attempted=1) +The fancy reports had a bug for a long time where any trailing whitespace on +the reported diff lines was stripped, making it impossible to see the +differences in line reported as different that differed only in the amount of +trailing whitespace. The whitespace still isn't particularly visible unless +you use NDIFF, but at least it is now there to be found. + + >>> def f(x): + ... r''' + ... >>> print('\n'.join(['a ', 'b'])) + ... a + ... b + ... ''' + + >>> test = doctest.DocTestFinder().find(f)[0] + >>> flags = doctest.REPORT_UDIFF + >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test) + ... # doctest: +ELLIPSIS + ********************************************************************** + File ..., line 3, in f + Failed example: + print('\n'.join(['a ', 'b'])) + Differences (context diff with expected followed by actual): + @@ -1,7 +1,7 @@ + -a + +a + b + TestResults(failed=1, attempted=1) + +NOTE: there is significant trailing whitespace on the +a line above; +*DO NOT STRIP IT* when editing this file. The REPORT_NDIFF flag causes failures to use the difflib.Differ algorithm used by the popular ndiff.py utility. This does intraline difference