UTF-8 characters in doctest

Peter Otten __peter__ at web.de
Wed Sep 19 14:16:09 CEST 2007


Bzyczek wrote:

> So my question is: Is it possible to run doctests with UTF-8
> characters? And if your answer will be YES, tell me please how...

Use raw strings in combination with explicit decoding and a little
try-and-error. E. g. this little gem passes ;)

# -*- coding: utf8 -*-
r"""
>>> f("äöü".decode("utf8"))
(u'\xe4\xf6\xfc',)
"""
def f(s):
    return (s,)
    
if __name__ == "__main__":
    import doctest
    doctest.testmod()

Peter



More information about the Python-list mailing list