2017-07-03 102 views
-1

我的項目有以下結構:的Python - InvocationError在TOX運行py.test和覆蓋測試

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

下一頁所有功能測試,我創建我想用於py.testscoverage tests的自動化的tox.ini文件。該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 

我如何修復我的tox.ini文件以使其工作?

+0

我沒有看到任何錯誤。複製/粘貼不足? – phd

+0

@phd看看以'收集10334個項目/ 167個錯誤ERROR'開始的行# – Ziva

+0

啊,對不起。似乎pytest在進口時發現了167個錯誤。 pytest測試通過沒有tox? – phd

回答

1

問題是你的兩個調用之間的差異。

[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 
相關問題