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