Python py.test:错误:无法识别的参数:--cov=ner_brands --cov-report=term-missing --cov-config
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26589990/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
py.test: error: unrecognized arguments: --cov=ner_brands --cov-report=term-missing --cov-config
提问by Hello lad
when I am trying to run my test through command line
当我尝试通过命令行运行我的测试时
py.test file_name.py
I got this error:
我收到此错误:
py.test: error: unrecognized arguments: --cov=ner_brands --cov-report=term-missing --cov-config
How can I fix this?
我怎样才能解决这个问题?
采纳答案by sdonk
pytest-cov packageis required if you want to pass --cov arguments to pytest, by default it should not be passed though. Are you using a modified version of py.test?
如果要将 --cov 参数传递给 pytest,则需要pytest-cov 包,但默认情况下不应传递它。您使用的是 py.test 的修改版本吗?
pip install pytest-cov
would fix your issue.
会解决你的问题。
回答by Samuel Phan
For those who use CentOS 6, the version of setuptoolsis old and you need to upgrade it also:
对于使用 CentOS 6 的用户,版本setuptools较旧,您还需要升级它:
pip install pytest-cov
pip install --upgrade setuptools
Just after installing pip install pytest-cov:
安装后pip install pytest-cov:
~ # py.test --version
This is pytest version 3.0.5, imported from /usr/lib/python2.6/site-packages/pytest.pyc
~ # pip install --upgrade setuptools
[...]
Successfully installed setuptools-30.3.0
~ # py.test --version
This is pytest version 3.0.5, imported from /usr/lib/python2.6/site-packages/pytest.pyc
setuptools registered plugins:
pytest-cov-2.4.0 at /usr/lib/python2.6/site-packages/pytest_cov/plugin.py
回答by Brontes
sdonk's answer helped me. But since I use pipenv, I had to run
sdonk 的回答帮助了我。但由于我使用pipenv,我不得不运行
pipenv install pytest_cov
回答by daveruinseverything
If the other answers here didn't work for you, you may have py.test installed somewhere else in your system. In my case, I ran into the issue described here inside a virtual environment, but it turned out that pytest was defaulting to my system installation (which did not have pytest-cov installed).
如果此处的其他答案对您不起作用,则您可能在系统中的其他位置安装了 py.test。就我而言,我在虚拟环境中遇到了此处描述的问题,但结果证明 pytest 默认为我的系统安装(未安装 pytest-cov)。
Deactivate your virtual environment or start a new shell and run the following to confirm:
停用您的虚拟环境或启动一个新的 shell 并运行以下命令进行确认:
pip3 freeze | grep pytest
(or pip freeze | grep pytestif you're running python2)
(或者pip freeze | grep pytest如果你正在运行 python2)
If you find it, try uninstalling it, then reactivate your virtual environment and try again.
如果找到,请尝试卸载它,然后重新激活您的虚拟环境并重试。
回答by Souradeep Nanda
Turns out my versions mismatched.
原来我的版本不匹配。
I changed the versions to
我将版本更改为
pytest="*"
pytest-cov="*"
and it started to work.
它开始起作用了。

