[英]pytest-cov not working with tox
This is my tox.ini
configuration 这是我的
tox.ini
配置
[tox]
envlist = py36
[testenv]
commands = pytest -vv --pep8 --flakes \
--cov=quest --cov-report \
term-missing --profile {posargs}
deps = -rrequirements.txt
When I run tox
, I get this error 当我运行
tox
,出现此错误
$ tox
GLOB sdist-make: /Users/hanxue/DrRed/quest-backend/setup.py
py36 inst-nodeps: /Users/hanxue/DrRed/quest-backend/.tox/dist/quest-3.0.0.zip
py36 installed: aniso8601==1.2.1,apipkg==1.4,argon2-cffi==16.3.0,cffi==1.10.0,click==6.7,configparser2==4.0.0,execnet==1.5.0,Flask==0.12.2,Flask-Cors==3.0.3,Flask-JWT==0.3.2,Flask-JWT-Extended==3.3.1,Flask-Login==0.4.0,Flask-RESTful==0.3.6,Flask-SocketIO==2.9.2,Flask-SQLAlchemy==2.3.2,gevent==1.2.2,gevent-websocket==0.10.1,greenlet==0.4.12,httplib2==0.10.3,itsdangerous==0.24,Jinja2==2.9.6,MarkupSafe==1.0,matrix==2.0.1,passlib==1.7.1,pep8==1.7.0,psycopg2==2.7.3,py==1.4.34,pycparser==2.18,pyflakes==1.6.0,PyJWT==1.4.2,pytest==3.2.3,pytest-cache==1.0,pytest-flakes==2.0.0,pytest-flask==0.10.0,pytest-pep8==1.0.6,python-dateutil==2.6.1,python-engineio==1.7.0,python-socketio==1.8.1,pytz==2017.2,quest==3.0.0,six==1.10.0,SQLAlchemy==1.1.12,Werkzeug==0.12.2
py36 runtests: PYTHONHASHSEED='65686078'
py36 runtests: commands[0] | pytest -vv --pep8 --flakes --cov=quest --cov-report term-missing --profile
usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --cov=quest --cov-report --profile
inifile: None
rootdir: /Users/hanxue/DrRed/quest-backend
ERROR: InvocationError: '/Users/hanxue/DrRed/quest-backend/.tox/py36/bin/pytest -vv --pep8 --flakes --cov=quest --cov-report term-missing --profile'
___________________________________ summary ____________________________________
ERROR: py36: commands failed
Notice that the list of installed packages do not include pytest-cov
and coverage
, even though those are explicitly included in my requirements.txt
and tox.ini
includes the line 请注意,已安装软件包的列表不包含
pytest-cov
和coverage
,即使它们明确包含在我的requirements.txt
并且tox.ini
包含以下行:
deps = -rrequirements.txt
Running the pytest
command directly works fine 直接运行
pytest
命令可以正常工作
$ PYTHONPATH=src/ pytest -vv --pep8 --flakes --cov=quest --cov-report term-missing --profile
How do I get the missing pytest-coverage
library to be installed by tox? 我该如何通过
pytest-coverage
安装缺少的pytest-coverage
库?
Contents of requirements.txt
内容
requirements.txt
aniso8601==1.2.1
argon2-cffi==16.3.0
cffi==1.10.0
click==6.7
colorama==0.3.9
configparser2==4.0.0
Coverage==4.4.1
Flask==0.12.2
Flask-RESTful==0.3.6
Flask-Login==0.4.0
Flask-Cors==3.0.3
Flask-JWT==0.3.2
Flask-JWT-Extended==3.3.1
Flask-SocketIO==2.9.2
Flask-SQLAlchemy==2.3.2
gevent==1.2.2
gevent-websocket==0.10.1
gprof2dot==2017.9.19
greenlet==0.4.12
httplib2==0.10.3
itsdangerous==0.24
Jinja2==2.9.6
MarkupSafe==1.0
matrix==2.0.1
passlib==1.7.1
psycopg2==2.7.3
pycparser==2.18
PyJWT==1.4.2
pytest==3.2.3
pytest-cache==1.0
pytest-colordots==1.1
pytest-cov==2.5.1
pytest-flakes==2.0.0
pytest-flask==0.10.0
pytest-pep8==1.0.6
pytest-profiling==1.2.11
python-dateutil==2.6.1
python-socketio==1.8.1
python-engineio==1.7.0
pytz==2017.2
six==1.10.0
SQLAlchemy==1.1.12
Werkzeug==0.12.2
It seems tox doesn't install additional requirements when requirements.txt
that's used in tox.ini
with deps = -rrequirements.txt
was changed after tox
has created its virtual environments. 看来,当TOX不安装额外的要求
requirements.txt
在的二手tox.ini
与deps = -rrequirements.txt
后改为tox
创造了虚拟环境。 I don't now if it's a bug in tox
. 我现在不知道这是否是
tox
的错误。
Either remove virtual environments ( rm -rf .tox
) and allow tox
to recreate them with the updated requirements.txt
or update existing virtual environments yourself: activate, pip install
, deactivate in a loop over all virtual environments in .tox/
. 删除虚拟环境(
rm -rf .tox
)并允许tox
使用更新的requirements.txt
重新创建它们,或者自己更新现有的虚拟环境:激活, pip install
, .tox/
所有虚拟环境的循环停用。 Something like 就像是
source .tox/py27/bin/activate
pip install --upgrade -r requirements.txt
deactivate
Upd . 更新 。 Seems to be an old known problem , still open and discussed.
似乎是一个古老的已知问题 ,仍在讨论中。
Reinstall virtualenv with tox when requirements.txt or setup.py changes 当requirements.txt或setup.py更改时,用tox重新安装virtualenv
In addition to @phd's answer , I found two other methods. 除了@phd的答案外 ,我还发现了另外两种方法。
Use tox-pip-extensions and add this to tox.ini
使用tox-pip-extensions并将其添加到
tox.ini
[tox]
tox_pip_extensions_ext_venv_update = true
Run --recreate
before running tox every time --recreate
运行tox之前运行--recreate
$ tox --recreate && tox
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.