Disable colorization if terminal does not support colors
adamchainz opened this issue · 0 comments
adamchainz commented
A failing test in a project I'm working on with pytest-icdiff
failed on CI where there is no terminal color support, and the output contains all the ANSI colorization characters which makes it much harder to read:
__________________________ test_foo ___________________________
[gw5] linux -- Python 3.7.3 /home/ciuser/.../python3
tests/test_foo.py:112: in test_foo
assert data == {
E AssertionError: assert equals failed
E �[m�[1;31m{'id': '00000000-0000-0000-0000-�[m �[1;32m{�[m
E �[m�[1;31m000000000002', 'created': '2020-�[m
...
E �[m �[1;32m 'created': '2020-09-24T00:00:0�[m
E �[m �[1;32m0Z',�[m
...
Colorization should only be done if sys.stdout.isatty()
returns True
- for example see my utility https://github.com/adamchainz/lifelogger/blob/master/lifelogger/utils.py#L10 .
Writing a PR now.