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: Unicode returns in doctest can make subsequent tests fail
Type: behavior Stage:
Components: Extension Modules, Tests Versions: Python 2.7, Python 2.6, Python 2.5
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, lregebro
Priority: normal Keywords: patch

Created on 2010-04-20 15:41 by lregebro, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
doctest_unicode.patch lregebro, 2010-04-20 15:41
Messages (2)
msg103728 - (view) Author: Lennart Regebro (lregebro) Date: 2010-04-20 15:41
If we return unicode, SpoofOut's buf variable becomes automagically converted to unicode. This means all subsequent output becomes converted to unicode, and if the output contains non-ascii characters that fails.

That means that 

    >>> print u'\xe9'.encode('utf-8')

Will work just fine, but

    >>> print u'abc'

    >>> print u'\xe9'.encode('utf-8')

Will fail.

The reason for this is that when "resetting" the doctest output only a truncate(0) is done, so the buf variable will continue to be unicode. I include tests + a patch that will set self.buf to '' if empty when trunkated. Other options are also possible, like changing the .truncate(0) to a .buf = '' but that's ugly, or adding a reset() method on SpoofOUt.
msg112288 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-08-01 08:22
Thanks, applied in r83392.
Date User Action Args
2022-04-11 14:57:00adminsetgithub: 52717
2010-08-01 08:22:32georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg112288

resolution: accepted
2010-04-20 15:41:12lregebrocreate