Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_doctest fails when run in verbose mode #45022

Closed
nnorwitz mannequin opened this issue Jun 1, 2007 · 10 comments
Closed

test_doctest fails when run in verbose mode #45022

nnorwitz mannequin opened this issue Jun 1, 2007 · 10 comments
Assignees
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@nnorwitz
Copy link
Mannequin

nnorwitz mannequin commented Jun 1, 2007

BPO 1729305
Nosy @ezio-melotti, @florentx
Files
  • doctest.patch: doctest patch that keeps track of encoding
  • test_doctest.patch: test for the bug
  • doctestfail.txt: traceback of the test failure
  • issue1729305_doctest_v2.diff: Patch, apply to trunk
  • issue1729305_doctest_py3k_v2.diff: Patch, apply to py3k
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/florentx'
    closed_at = <Date 2010-02-27.14:39:47.543>
    created_at = <Date 2007-06-01.05:16:47.000>
    labels = ['type-bug', 'tests']
    title = 'test_doctest fails when run in verbose mode'
    updated_at = <Date 2010-02-27.15:24:20.508>
    user = 'https://bugs.python.org/nnorwitz'

    bugs.python.org fields:

    activity = <Date 2010-02-27.15:24:20.508>
    actor = 'flox'
    assignee = 'flox'
    closed = True
    closed_date = <Date 2010-02-27.14:39:47.543>
    closer = 'flox'
    components = ['Tests']
    creation = <Date 2007-06-01.05:16:47.000>
    creator = 'nnorwitz'
    dependencies = []
    files = ['9533', '9534', '15102', '16385', '16387']
    hgrepos = []
    issue_num = 1729305
    keywords = ['patch']
    message_count = 10.0
    messages = ['32174', '62896', '62897', '93861', '96819', '98234', '98235', '100180', '100184', '100185']
    nosy_count = 4.0
    nosy_names = ['nnorwitz', 'mbeachy', 'ezio.melotti', 'flox']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1729305'
    versions = ['Python 2.6', 'Python 3.1', 'Python 2.7', 'Python 3.2']

    @nnorwitz
    Copy link
    Mannequin Author

    nnorwitz mannequin commented Jun 1, 2007

    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)

    @nnorwitz nnorwitz mannequin added stdlib Python modules in the Lib dir labels Jun 1, 2007
    @mbeachy
    Copy link
    Mannequin

    mbeachy mannequin commented Feb 24, 2008

    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

    @mbeachy
    Copy link
    Mannequin

    mbeachy mannequin commented Feb 24, 2008

    Here's a patch for test_doctest.py that checks the problem has been fixed.

    @ezio-melotti
    Copy link
    Member

    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.

    @florentx
    Copy link
    Mannequin

    florentx mannequin commented Dec 22, 2009

    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)

    @florentx florentx mannequin added tests Tests in the Lib/test dir and removed stdlib Python modules in the Lib dir labels Dec 22, 2009
    @florentx
    Copy link
    Mannequin

    florentx mannequin commented Jan 24, 2010

    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

    @florentx
    Copy link
    Mannequin

    florentx mannequin commented Jan 24, 2010

    And for Python 3. (Slightly different)

    @florentx florentx mannequin self-assigned this Feb 26, 2010
    @florentx florentx mannequin added the type-bug An unexpected behavior, bug, or error label Feb 26, 2010
    @florentx florentx mannequin self-assigned this Feb 26, 2010
    @florentx florentx mannequin added the type-bug An unexpected behavior, bug, or error label Feb 26, 2010
    @florentx
    Copy link
    Mannequin

    florentx mannequin commented Feb 27, 2010

    This patch is simpler, and it fixes bpo-7667 too.

    @florentx
    Copy link
    Mannequin

    florentx mannequin commented Feb 27, 2010

    For Py3k, it is enough to "backslashreplace" the errors on "write".

    @florentx
    Copy link
    Mannequin

    florentx mannequin commented Feb 27, 2010

    Fixed in r78488 and r78493.

    @florentx florentx mannequin closed this as completed Feb 27, 2010
    @florentx florentx mannequin closed this as completed Feb 27, 2010
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant