@@ -2355,7 +2355,12 @@ def test_unittest_reportflags():
23552355 Then the default eporting options are ignored:
23562356
23572357 >>> result = suite.run(unittest.TestResult())
2358- >>> print result.failures[0][1] # doctest: +ELLIPSIS
2358+ """
2359+ """
2360+ *NOTE*: These doctest are intentionally not placed in raw string to depict
2361+ the trailing whitespace using `\x20 ` in the diff below.
2362+
2363+ >>> print(result.failures[0][1]) # doctest: +ELLIPSIS
23592364 Traceback ...
23602365 Failed example:
23612366 favorite_color
@@ -2368,7 +2373,7 @@ def test_unittest_reportflags():
23682373 Differences (ndiff with -expected +actual):
23692374 a
23702375 - <BLANKLINE>
2371- +
2376+ +\x20
23722377 b
23732378 <BLANKLINE>
23742379 <BLANKLINE>
@@ -2717,6 +2722,47 @@ def old_test4(): """
27172722 TestResults(failed=0, attempted=4)
27182723"""
27192724
2725+ def test_no_trailing_whitespace_stripping ():
2726+ r"""
2727+ The fancy reports had a bug for a long time where any trailing whitespace on
2728+ the reported diff lines was stripped, making it impossible to see the
2729+ differences in line reported as different that differed only in the amount of
2730+ trailing whitespace. The whitespace still isn't particularly visible unless
2731+ you use NDIFF, but at least it is now there to be found.
2732+
2733+ *NOTE*: This snippet was intentionally put inside a raw string to get rid of
2734+ leading whitespace error in executing the example below
2735+
2736+ >>> def f(x):
2737+ ... r'''
2738+ ... >>> print('\n'.join(['a ', 'b']))
2739+ ... a
2740+ ... b
2741+ ... '''
2742+ """
2743+ """
2744+ *NOTE*: These doctest are not placed in raw string to depict the trailing whitespace
2745+ using `\x20 `
2746+
2747+ >>> test = doctest.DocTestFinder().find(f)[0]
2748+ >>> flags = doctest.REPORT_NDIFF
2749+ >>> doctest.DocTestRunner(verbose=False, optionflags=flags).run(test)
2750+ ... # doctest: +ELLIPSIS
2751+ **********************************************************************
2752+ File ..., line 3, in f
2753+ Failed example:
2754+ print('\n '.join(['a ', 'b']))
2755+ Differences (ndiff with -expected +actual):
2756+ - a
2757+ + a
2758+ b
2759+ TestResults(failed=1, attempted=1)
2760+
2761+ *NOTE*: `\x20 ` is for checking the trailing whitespace on the +a line above.
2762+ We cannot use actual spaces there, as a commit hook prevents from committing
2763+ patches that contain trailing whitespace. More info on Issue 24746.
2764+ """
2765+
27202766######################################################################
27212767## Main
27222768######################################################################
0 commit comments