作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的项目具有以下结构:
my_project
|
setup.py
tox.ini
src
|
core_functions.py
client.py
server.py
sql_database.py
tests.py
tests.py
文件包含文件
client.py, server.py, sql_database.py, core_functions.py
中所有函数的测试
tox.ini
我想用于自动化
py.tests
的文件和
coverage tests
. tox.ini 文件的结构如下:
[tox]
envlist = py27,cov
[testenv]
commands = py.test -sv --doctest-modules my_project/__init__.py my_project/tests.py
[testenv:py27]
commands = coverage erase
coverage run --source=my_project -m pytest
coverage report -m
deps = pytest
tox
py.tests 成功,但覆盖测试失败并出现以下错误:
============== test session starts ===================
platform darwin -- Python 2.7.13, pytest-3.1.1, py-1.4.33, pluggy-0.4.0
rootdir: /Users/xyz/Documents/ProjectGit/MyProject/my_project, inifile:
plugins: cov-2.5.1
collecting 10334 items / 167 errorsERROR: InvocationError:
'/Users/xyz/Documents/ProjectGit/MyProject/my_project/.tox/py27/bin/coverage run --source=my_project -m pytest'
cov inst-nodeps: /Users/xyz/Documents/ProjectGit/MyProject/my_project/.tox/dist/my_project-0.0.1.zip
cov installed: asn1crypto==0.22.0,attrs==17.2.0,Automat==0.6.0,bitarray==0.8.1,boto3==1.4.4,
botocore==1.5.59,cffi==1.10.0,constantly==15.1.0,coverage==4.4.1,cryptography==1.9,
cycler==0.10.0,docutils==0.13.1,enum34==1.1.6,Fabric==1.13.2,functools32==3.2.3.post2,
future==0.16.0,futures==3.1.1,idna==2.5,incremental==17.5.0,ipaddress==1.0.18,jmespath==0.9.3,
my_project==0.0.1,matplotlib==2.0.2,msgpack-python==0.4.8,numpy==1.12.1,paramiko==2.1.2,
Paver==1.2.4,petlib==0.0.41,py==1.4.33,pyasn1==0.2.3,pybloom==1.1,pycparser==2.17,
pyparsing==2.2.0,pytest==3.1.1,pytest-cov==2.5.1,python-dateutil==2.6.0,pytz==2017.2,
s3transfer==0.1.10,scapy==2.3.3,scipy==0.19.0,six==1.10.0,sphinxmix==0.0.6,
subprocess32==3.2.7,Twisted==17.1.0,zope.interface==4.4.1
cov runtests: PYTHONHASHSEED='3903710496'
cov runtests: commands[0] | py.test -sv --doctest-modules my_project/__init__.py my_project/tests.py
最佳答案
问题在于您的两次调用之间的差异。
在 [testenv]
你基本上是在打电话:
py.test -sv --doctest-modules my_project/__init__.py my_project/tests.py
py.test
py.test
不带参数将从当前目录递归并尝试发现测试。这个一般
不是 你想要什么(你不关心测试 stdlib,以及你添加到 virtualenv 的所有依赖项等)
coverage run --source=my_project -m pytest -sv --doctest-modules my_project/__init__.py my_project/tests.py
关于Python - 运行 py.test 和覆盖测试的 tox 中的 InvocationError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44884828/
我的项目具有以下结构: my_project | setup.py tox.ini src | core_functions.py client.py server.py
我一直在学习如何在 tox 中为我的 python 项目进行测试。 我有(应该是)一个相当标准的 tox 初始化文件,如下所示: [tox] envlist=py27,flake8 ... [test
我是一名优秀的程序员,十分优秀!