Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64154

doctests compatibility for python 2 & python 3

From Robin Becker <robin@reportlab.com>
Subject doctests compatibility for python 2 & python 3
Date 2014-01-17 11:16 +0000
Newsgroups comp.lang.python
Message-ID <mailman.5634.1389957389.18130.python-list@python.org> (permalink)

Show all headers | View raw


I have some problems making some doctests for python2 code compatible with 
python3. The problem is that as part of our approach we are converting the code 
to use unicode internally. So we allow eihter byte strings or unicode in inputs, 
but we are trying to convert to unicode outputs.

That makes doctests quite hard as

def func(a):
     """
     >>> func(u'aaa')
     'aaa'
     """
     return a

fails in python2 whilst

def func(a):
     """
     >>> func(u'aaa')
     u'aaa'
     """
     return a

fails in python3. Aside from changing the tests so they look like
     """
     >>> func(u'aaa')==u'aaa'
     True
     """
which make the test utility harder. If the test fails I don't see the actual 
outcome and expected I see expected True got False.

Is there an easy way to make these kinds of tests work in python 2 & 3?
-- 
Robin Becker

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

doctests compatibility for python 2 & python 3 Robin Becker <robin@reportlab.com> - 2014-01-17 11:16 +0000
  Re: doctests compatibility for python 2 & python 3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-17 11:41 +0000
    Re: doctests compatibility for python 2 & python 3 Robin Becker <robin@reportlab.com> - 2014-01-17 12:12 +0000
      Re: doctests compatibility for python 2 & python 3 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-17 15:27 +0000
        Re: doctests compatibility for python 2 & python 3 Robin Becker <robin@reportlab.com> - 2014-01-17 16:17 +0000

csiph-web