Issue 7981: False failure with doctest NORMALIZE_WHITESPACE in 3.1.1 (original) (raw)

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

Files
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.") # doctest: +NORMALIZE_WHITESPACE Expected: This text contains weird spacing. Got: 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.") # doctest: +NORMALIZE_WHITESPACE
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, .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"). xxxx
History
Date User Action Args
2022-04-11 14:56:57 admin set github: 52229
2013-02-20 03:06:32 r.david.murray set status: open -> closednosy: + r.david.murraymessages: + resolution: not a bugstage: resolved
2010-05-17 18:38:50 trambalda set messages: +
2010-05-17 18:16:54 trambalda set nosy: + trambaldamessages: +
2010-02-22 13:01:02 dastagg create