@@ -2355,7 +2355,12 @@ def test_unittest_reportflags():
2355
2355
Then the default eporting options are ignored:
2356
2356
2357
2357
>>> 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
2359
2364
Traceback ...
2360
2365
Failed example:
2361
2366
favorite_color
@@ -2368,7 +2373,7 @@ def test_unittest_reportflags():
2368
2373
Differences (ndiff with -expected +actual):
2369
2374
a
2370
2375
- <BLANKLINE>
2371
- +
2376
+ +\x20
2372
2377
b
2373
2378
<BLANKLINE>
2374
2379
<BLANKLINE>
@@ -2717,6 +2722,47 @@ def old_test4(): """
2717
2722
TestResults(failed=0, attempted=4)
2718
2723
"""
2719
2724
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
+
2720
2766
######################################################################
2721
2767
## Main
2722
2768
######################################################################
0 commit comments