How do I force pytest to write color output?

↘锁芯ラ 提交于 2019-12-03 08:16:52

问题


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.


回答1:


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"



回答2:


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



来源:https://stackoverflow.com/questions/17069007/how-do-i-force-pytest-to-write-color-output

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!