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