@@ -2451,6 +2451,11 @@ def test_unittest_reportflags():
24512451 Then the default eporting options are ignored:
24522452
24532453 >>> result = suite.run(unittest.TestResult())
2454+ """
2455+ """
2456+ *NOTE*: These doctest are intentionally not placed in raw string to depict
2457+ the trailing whitespace using `\x20 ` in the diff below.
2458+
24542459 >>> print(result.failures[0][1]) # doctest: +ELLIPSIS
24552460 Traceback ...
24562461 Failed example:
@@ -2464,7 +2469,7 @@ def test_unittest_reportflags():
24642469 Differences (ndiff with -expected +actual):
24652470 a
24662471 - <BLANKLINE>
2467- +
2472+ +\x20
24682473 b
24692474 <BLANKLINE>
24702475 <BLANKLINE>
@@ -2953,6 +2958,47 @@ def test_CLI(): r"""
29532958
29542959"""
29552960
2961+ def test_no_trailing_whitespace_stripping ():
2962+ r"""
2963+ The fancy reports had a bug for a long time where any trailing whitespace on
2964+ the reported diff lines was stripped, making it impossible to see the
2965+ differences in line reported as different that differed only in the amount of
2966+ trailing whitespace. The whitespace still isn't particularly visible unless
2967+ you use NDIFF, but at least it is now there to be found.
2968+
2969+ *NOTE*: This snippet was intentionally put inside a raw string to get rid of
2970+ leading whitespace error in executing the example below
2971+
2972+ >>> def f(x):
2973+ ... r'''
2974+ ... >>> print('\n'.join(['a ', 'b']))
2975+ ... a
2976+ ... b
2977+ ... '''
2978+ """
2979+ """
2980+ *NOTE*: These doctest are not placed in raw string to depict the trailing whitespace
2981+ using `\x20 `
2982+
2983+ >>> test = doctest.DocTestFinder().find(f)[0]
2984+ >>> flags = doctest.REPORT_NDIFF
2985+ >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test)
2986+ ... # doctest: +ELLIPSIS
2987+ **********************************************************************
2988+ File ..., line 3, in f
2989+ Failed example:
2990+ print('\n '.join(['a ', 'b']))
2991+ Differences (ndiff with -expected +actual):
2992+ - a
2993+ + a
2994+ b
2995+ TestResults(failed=1, attempted=1)
2996+
2997+ *NOTE*: `\x20 ` is for checking the trailing whitespace on the +a line above.
2998+ We cannot use actual spaces there, as a commit hook prevents from committing
2999+ patches that contain trailing whitespace. More info on Issue 24746.
3000+ """
3001+
29563002######################################################################
29573003## Main
29583004######################################################################
0 commit comments