@@ -2450,6 +2450,11 @@ def test_unittest_reportflags():
2450
2450
Then the default eporting options are ignored:
2451
2451
2452
2452
>>> 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
+
2453
2458
>>> print(result.failures[0][1]) # doctest: +ELLIPSIS
2454
2459
Traceback ...
2455
2460
Failed example:
@@ -2463,7 +2468,7 @@ def test_unittest_reportflags():
2463
2468
Differences (ndiff with -expected +actual):
2464
2469
a
2465
2470
- <BLANKLINE>
2466
- +
2471
+ +\x20
2467
2472
b
2468
2473
<BLANKLINE>
2469
2474
<BLANKLINE>
@@ -2952,6 +2957,47 @@ def test_CLI(): r"""
2952
2957
2953
2958
"""
2954
2959
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
+
2955
3001
######################################################################
2956
3002
## Main
2957
3003
######################################################################
0 commit comments