On Mar 05, 2010, at 05:11 AM, Martin v. Löwis wrote:

>Johan Harjano ran into an interesting problem when trying to run the
>Django test suite under Python 3.1.
>
>Django has doctests of the form
>
>>>> a6.headline
>u'Default headline'
>
>Even when converting the doctest with 2to3, the expected output is
>unmodified. However, in 3.x, the expected output will change (i.e. not
>produce an u"" prefix anymore).

For this reason, I always recommend using print, even though...

>Now, it might be possible to reformulate the test case (e.g. use print()
>instead of relying on repr), however, this is undesirable as a) the test
>should continue to test in 2.x that the result object is a unicode
>string, and b) it makes the test less readable.

If you really want to test that it's a unicode, shouldn't you actually test
its type?  (I'm not sure what would happen with that under 2to3.)  Besides,
the type of the string is very rarely important, so I think the u-prefix and
quotes is mostly just noise.

>I would like to find a solution where this gets automatically corrected,
>e.g. through 2to3, or through changes to doctest, or through changes of
>str.__repr__.

I think Michael was also talking about changes to doctest that would
automatically sort dictionaries and sets.  Again, it's not hard to write
doctests correctly, but it's surprisingly common to implicitly rely on sort
order.

I think the right place to change these is in doctest.

-Barry

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to