2017-06-12 114 views
0

我用于运行在Makefile中我的包测试,以此来在一个执行三项任务:建立一个虚拟的环境,安装要求和调用测试套件与相应的参数:与Makefile中集成setup.py运行测试

test: venv 
    env/bin/pip install -r test_requirements.txt 
    env/bin/nosetests --rednose --with-coverage --cover-pagacke my_module 

然后我读了requirements.txt文件支持setup.py的气馁,所以我修改了setup.py文件旨在获得相同的结果:

setup(
    ... 
    tests_require=['nose', 'rednose', 'coverage'], 
    test_suite=['nose.collector']) 

现在我能修改Makefile文件与

test: venv 
    coverage run --source=my_module/ setup.py test 

但需要在运行setup.py文件,然后再安装测试的依赖。我也不确定如何包含其他参数,如rednose。做这个的最好方式是什么?

+0

“在一个执行三项任务:建立一个虚拟的环境,安装要求和调用测试套件” - 这是究竟是什么[tox](https://tox.readthedocs.io)。 – jwodder

+0

requirements.txt没有错,他们并不气馁。 setup.py和requirements.txt只是有不同的[角色](https://caremad.io/posts/2013/07/setup-vs-requirement/)。说了我也推荐使用tox。 – phd

回答

0

弓形虫是好的,所有的,但这里是如何做到这一点,而无需预先安装任何其他软件包。

列表测试依赖关系setup_requires代替tests_requiresetup.py文件

setup(
    setup_requires=['nose', 'rednose', 'coverage'], 
    install_requires=[] # fill in other arguments as usual 
) 

任选地添加测试参数到setup.cfg文件。

[nosetests] 
rednose=1 
detailed-errors=1 
with-coverage=1 
cover-package=server 
cover-xml=1 
verbosity=2 

用下面的命令运行测试

python setup.py nosetests 

来源:http://nose.readthedocs.io/en/latest/api/commands.html

+0

** **覆盖工程** tests_require罚款** **可是** rednose需要在** ** setup_requires。你知道那是为什么吗? –