Skip to content

Commit

Permalink
Fix decode error in Python 2 for doctests in docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Jun 13, 2017
1 parent 0908f40 commit 47a724b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 0 additions & 4 deletions _pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ def collect(self):
name = self.fspath.basename
globs = {'__name__': '__main__'}


optionflags = get_optionflags(self)
runner = doctest.DebugRunner(verbose=0, optionflags=optionflags,
checker=_get_checker())
Expand Down Expand Up @@ -218,9 +217,6 @@ def collect(self):
runner = doctest.DebugRunner(verbose=0, optionflags=optionflags,
checker=_get_checker())

encoding = self.config.getini("doctest_encoding")
_fix_spoof_python2(runner, encoding)

for test in finder.find(module, module.__name__):
if test.examples: # skip empty doctests
yield DoctestItem(test.name, self, runner, test)
Expand Down
1 change: 1 addition & 0 deletions changelog/2434.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix decode error in Python 2 for doctests in docstrings.
19 changes: 19 additions & 0 deletions testing/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,25 @@ def test_unicode_doctest(self, testdir):
'*1 failed*',
])

def test_unicode_doctest_module(self, testdir):
"""
Test case for issue 2434: DecodeError on Python 2 when doctest docstring
contains non-ascii characters.
"""
p = testdir.makepyfile(test_unicode_doctest_module="""
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals
def fix_bad_unicode(text):
'''
>>> print(fix_bad_unicode('único'))
único
'''
return "único"
""")
result = testdir.runpytest(p, '--doctest-modules')
result.stdout.fnmatch_lines(['* 1 passed *'])


class TestLiterals(object):

Expand Down

0 comments on commit 47a724b

Please sign in to comment.