[New-bugs-announce] [issue8471] Unicode returns in doctest can make subsequent tests fail

Lennart Regebro report at bugs.python.org
Tue Apr 20 17:41:13 CEST 2010


New submission from Lennart Regebro <regebro at gmail.com>:

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'
    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.

----------
components: Extension Modules, Tests
files: doctest_unicode.patch
keywords: patch
messages: 103728
nosy: lregebro
severity: normal
status: open
title: Unicode returns in doctest can make subsequent tests fail
type: behavior
versions: Python 2.5, Python 2.6, Python 2.7
Added file: http://bugs.python.org/file17007/doctest_unicode.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8471>
_______________________________________


More information about the New-bugs-announce mailing list