How do I force pytest to show the results in color, even when writing to a pipe? There does not seem to be any command line option to do so.
Asked
Active
Viewed 1.5k times
3 Answers
76
As of 2.5.0 py.test has the option --color=yes
As of 2.7.0, it should be also possible to do:
export PYTEST_ADDOPTS="--color=yes"

Johan Lübcke
- 19,666
- 8
- 38
- 35
8
The "py" library that pytest uses will not use color if it doesn't detect a terminal. I ended up making a change to it to allow setting an enviroment variable (PY_FORCE_COLOR=1
) to force the color.
I submitted a PR for this: https://bitbucket.org/hpk42/py/pull-request/10/add-an-environment-variable-py_force_color
For now, I install my fork to do this:
pip install hg+https://msabramo@bitbucket.org/msabramo/py@py_force_color

Marc Abramowitz
- 3,447
- 3
- 24
- 30
-
4as said there, i think we should introduce a direct ``--color=yes|no|auto`` option to pytest. – hpk42 Nov 18 '13 at 09:53
-
4py.test now has the option that @hpk42 mentioned. – Marc Abramowitz Jan 26 '14 at 08:18
0
There's a library that I have not tried but sounds promising. It's pytest-rich
. See: https://github.com/nicoddemus/pytest-rich

astrochun
- 1,642
- 2
- 7
- 18