How do I force pytest to write color output?

2020-05-23 02:07发布

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.

标签: pytest
2条回答
姐就是有狂的资本
2楼-- · 2020-05-23 02:45

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"
查看更多
家丑人穷心不美
3楼-- · 2020-05-23 02:47

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

查看更多
登录 后发表回答