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.

classification
Title: test_doctest fails when run in verbose mode
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: flox Nosy List: ezio.melotti, flox, mbeachy, nnorwitz
Priority: normal Keywords: patch

Created on 2007-06-01 05:16 by nnorwitz, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
doctest.patch mbeachy, 2008-02-24 13:10 doctest patch that keeps track of encoding
test_doctest.patch mbeachy, 2008-02-24 13:12 test for the bug
doctestfail.txt ezio.melotti, 2009-10-11 16:09 traceback of the test failure
issue1729305_doctest_v2.diff flox, 2010-02-27 11:06 Patch, apply to trunk
issue1729305_doctest_py3k_v2.diff flox, 2010-02-27 12:05 Patch, apply to py3k
Messages (10)
msg32174 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2007-06-01 05:16
This happens on trunk, p3yk branch and 2.5.

Trying:
    doctest.testfile('test_doctest4.txt', encoding='utf-8')
Expecting:
    (0, 4)
test test_doctest crashed -- <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode characters in position 301-302: ordinal not in range(128)
Traceback (most recent call last):
  File "./Lib/test/regrtest.py", line 557, in runtest_inner
    indirect_test()
  File "/home/neal/python/dev/r25/Lib/test/test_doctest.py", line 2402, in test_main
    test_support.run_doctest(test_doctest, verbosity=True)
  File "/home/neal/python/dev/r25/Lib/test/test_support.py", line 467, in run_doctest
    f, t = doctest.testmod(module, verbose=verbosity)
  File "/home/neal/python/dev/r25/Lib/doctest.py", line 1799, in testmod
    runner.run(test)
  File "/home/neal/python/dev/r25/Lib/doctest.py", line 1345, in run
    return self.__run(test, compileflags, out)
  File "/home/neal/python/dev/r25/Lib/doctest.py", line 1261, in __run
    self.report_failure(out, test, example, got)
  File "/home/neal/python/dev/r25/Lib/doctest.py", line 1125, in report_failure
    self._checker.output_difference(example, got, self.optionflags))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 301-302: ordinal not in range(128)
msg62896 - (view) Author: Mike Beachy (mbeachy) Date: 2008-02-24 13:10
The basic issue here is that running in verbose mode echoes back the
expected values from the file, so the results from non-ascii doctest
files must be encoded before printing.

It looks to me like the DocTestRunner class must grow an '_encoding'
attribute to keep track of how to encode any verbose output. I've
attached a patch that does this.

Happy post bug day!
Mike
msg62897 - (view) Author: Mike Beachy (mbeachy) Date: 2008-02-24 13:12
Here's a patch for test_doctest.py that checks the problem has been fixed.
msg93861 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-10-11 16:09
This test still fail on Win7 with Py2.6.3rc1 in verbose mode, it works
fine in normal mode.
I attached a file with the traceback.
msg96819 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2009-12-22 23:31
It still occurs on trunk.

test test_doctest crashed -- <type 'exceptions.UnicodeEncodeError'>:
  'ascii' codec can't encode characters in position 343-344:
    ordinal not in range(128)
msg98234 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-01-24 16:49
The patch did not work with latest trunk.

Here is an updated version of the patch.

Patch tested with different commands:
~ $ ./python -m test.regrtest test_doctest
~ $ ./python -m test.regrtest -v test_doctest
~ $ ./python -m test.regrtest -v test_doctest |less
~ $ ./python -3 -Wd Lib/test/regrtest.py -v test_doctest |less
msg98235 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-01-24 16:53
And for Python 3. (Slightly different)
msg100180 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-02-27 11:06
This patch is simpler, and it fixes #7667 too.
msg100184 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-02-27 12:06
For Py3k, it is enough to "backslashreplace" the errors on "write".
msg100185 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-02-27 14:39
Fixed in r78488 and r78493.
History
Date User Action Args
2022-04-11 14:56:24adminsetgithub: 45022
2010-03-22 22:46:17floxunlinkissue7667 superseder
2010-03-16 16:37:27r.david.murraylinkissue8157 superseder
2010-02-27 15:24:20floxsetresolution: accepted -> fixed
2010-02-27 14:39:47floxsetstatus: open -> closed
resolution: accepted
messages: + msg100185

stage: patch review -> resolved
2010-02-27 12:06:53floxsetmessages: + msg100184
2010-02-27 12:06:03floxlinkissue7667 superseder
2010-02-27 12:05:05floxsetfiles: + issue1729305_doctest_py3k_v2.diff
2010-02-27 11:06:35floxsetfiles: + issue1729305_doctest_v2.diff

messages: + msg100180
2010-02-27 11:05:08floxsetfiles: - issue1729305_doctest.diff
2010-02-27 11:05:04floxsetfiles: - issue1729305_doctest_py3k.diff
2010-02-26 11:28:05floxsetassignee: flox
type: behavior
2010-01-24 16:53:59floxsetfiles: + issue1729305_doctest_py3k.diff

messages: + msg98235
stage: patch review
2010-01-24 16:49:40floxsetfiles: + issue1729305_doctest.diff

messages: + msg98234
versions: + Python 3.1, Python 3.2
2009-12-22 23:31:33floxsetversions: + Python 2.7
nosy: + flox

messages: + msg96819

components: + Tests, - Library (Lib)
2009-10-11 16:09:44ezio.melottisetfiles: + doctestfail.txt
versions: + Python 2.6, - Python 2.5
nosy: + ezio.melotti

messages: + msg93861
2008-02-24 13:12:37mbeachysetfiles: + test_doctest.patch
messages: + msg62897
2008-02-24 13:10:51mbeachysetfiles: + doctest.patch
keywords: + patch
messages: + msg62896
nosy: + mbeachy
2007-06-01 05:16:47nnorwitzcreate