Icecream produces strange output when used within doctest
Hello,
I tried to use ic within doctests (python 3.11.8) : import doctest from icecream import ic
def tester(): """
tester() """ a = ic(5*3) print(f"{a=}")
if name == 'main': doctest.testmod()
doctest will return
[38;5;247mic[39m[38;5;245m|[39m[38;5;245m [39m[38;5;36m5[39m[38;5;245m*[39m[38;5;36m3[39m[38;5;245m:[39m[38;5;245m [39m[38;5;36m15[39m
File "C:/Users/U070420/Downloads/ictest.py", line 6, in main.tester Failed example: tester() Expected nothing Got: a=15
1 items had failures: 1 of 1 in main.tester Test Failed 1 failures.
where the print works as expected, but icecream produces strange output.
Any way around this?
Thank you!
Best regards, Torsten
Which version of icecream were you using?
I have reformatted the code you have provided so that it can be easily copied:
from icecream import ic
def tester():
"""
>>> tester()
>>> a = ic(5*3)
>>> print(f"{a=}")
"""
if __name__ == '__main__':
import doctest
doctest.testmod()
I tested the above code with icecream 2.1.3 in python 3.11.8 and got the expected output:
ic| 5*3: 15
@rodigu : Sorry for the late reply, I seemingly missed the notification by git. Thanks for taking a look. I rechecked. I used it from the IDLE. If I run it from the command line (or started from CICD), I get the same result like you. Seems to be an issue with the IC and IDLE ...
We are able to close the tracker.
Best regards