I have some code for which I have some doctest, e.g.
def foo(x):
"""
Examples:
>>> s = foo()
>>> print(repr(s))
'\x1b[0;35mfoo\x1b[0m \x1b[0;36mbar\x1b[0m'
>>> print(s)
foo bar
"""
return '\u001b[0;35mfoo\u001b[0m \u001b[0;36mbar\u001b[0m'
Of course, in a ANSI-escape capable terminal, the last print()
is actually colored.
However, if I run doctest
here, I will get a failing test.
How could I solve this?
I was hoping either to have a way of inserting ANSI escapes or, preferably, a doctest directive for ignoring them, but I could not find any information on this in the docs.