This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: False failure with doctest NORMALIZE_WHITESPACE in 3.1.1
Type: behavior Stage: resolved
Components: Tests Versions:
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: dastagg, r.david.murray, trambalda
Priority: normal Keywords:

Created on 2010-02-22 13:01 by dastagg, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
test2.txt dastagg, 2010-02-22 13:01 Two tests that use the NORMALIZE_WHITESPACE directive
Messages (4)
msg99729 - (view) Author: David Stagowski (dastagg) Date: 2010-02-22 13:01
Running the same test file in both:
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
Python 3.1.1 (r311:74480, Feb 14 2010, 15:55:41) 

python -m doctest test2.txt and
python3 -m doctest test2.txt

No failure in 2.6.2.
For 3.1.1:

File "test2.txt", line 9, in test2.txt
Failed example:
    sys.stdout.write("This text\n contains weird     spacing.")
    This text contains weird spacing.
    This text
     contains weird     spacing.38
1 items had failures:
   1 of   3 in test2.txt
***Test Failed*** 1 failures.
msg105927 - (view) Author: trambalda (trambalda) Date: 2010-05-17 18:16
Same problem in 2.6.4 r264:75708 and 3.1 r31:73574
msg105928 - (view) Author: trambalda (trambalda) Date: 2010-05-17 18:38
but with print() it works:

    print("This text\n contains weird     spacing.")
msg182464 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-02-20 03:06
This doesn't have anything to do with NORMALIZE_WHITESPACE.

In python3, <file>.write returns the number of bytes written, instead of None.  If you add the 38 to the end of your test line, the test will pass.

This is not a bug in doctest, but a difference in 'write' behavior between Python2 and Python3.  You can write doctests that will pass on both by explicitly discarding the return value:

    >>> _ = sys.stdout.write("xxxx").
Date User Action Args
2022-04-11 14:56:57adminsetgithub: 52229
2013-02-20 03:06:32r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg182464

resolution: not a bug
stage: resolved
2010-05-17 18:38:50trambaldasetmessages: + msg105928
2010-05-17 18:16:54trambaldasetnosy: + trambalda
messages: + msg105927
2010-02-22 13:01:02dastaggcreate