簡體   English   中英

將setup.py與Makefile集成以運行測試

[英]Integrating setup.py with Makefile to run tests

我曾經從Makefile運行我的軟件包的測試,以一種方式執行以下三個任務:設置虛擬環境,安裝要求並使用相應的參數調用測試套件:

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

然后,我不建議使用setup.py來讀取requirements.txt文件,因此我修改了setup.py文件,旨在獲得相同的結果:

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

現在我可以用

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

但這需要在運行setup.py文件之前安裝測試依賴項。 我也不確定如何包括其他參數,例如rednose。 做這個的最好方式是什么?

Tox很不錯,但是這里是無需預先安裝任何其他軟件包的方法。

setup.py文件中將測試依賴項列為setup_requires而不是tests_require

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM