Python与Coveralls.io API的接口
python-coveralls的Python项目详细描述
这个包提供了一个与https://coveralls.ioapi接口的模块。
安装包
使用pip:
$ pip install python-coveralls
…或者简单地将其添加到您的需求中。
配置
如果您不使用travis,《python工作服》在存储库的根级别使用.coveralls.yml文件来配置选项。 唯一需要的选项是repo_token(可以在存储库的工作服页面上找到),以指定项目映射到工作服上的哪个项目。 另一个重要的选项是service_name,它允许您指定工作服应在哪里查找有关生成的其他信息。这可以是任何字符串,但使用travis ci或travis pro将允许工作服获取分支数据、对拉取请求进行评论等。 为travis pro配置的.coveralls.yml文件:
repo_token:abcdef1234569abdcefservice_name:travis-proparallel:true# if the CI is running your build in parallel
如果不希望repo_token受源代码管理,请在coveralls命令中设置它:
COVERALLS_REPO_TOKEN=abcdef1234569abdcef coveralls
travis.yml
创建一个.coverage文件,您可以使用coverage, pytest-cov,或 nosexcover。 然后,您可以在成功后添加步骤:
coveralls
它应该看起来像:
language:pythonpython:-"2.6"-"2.7"install:-pip install -e . --use-mirrorsbefore_script:-pip install -r test_requirements.txt --use-mirrors-git clone https://github.com/z4r/python-coveralls-example.git-cd python-coveralls-example-git checkout -qf 17b8119796516195527dcb4f454a2ebd41d60244-py.test example/tests.py --cov=example-cd -script:-py.test coveralls/tests.py --doctest-modules --pep8 coveralls -v --cov coveralls --cov-report term-missingafter_success:-coveralls
工作服选项
您可能不需要配置任何内容,但如果您自定义了覆盖范围的某个选项,则也可以将其添加到工作服中:
$ coveralls -h usage: coveralls [-h] [--coveralls_url COVERALLS_URL] [--base_dir BASE_DIR] [--data_file DATA_FILE] [--config_file CONFIG_FILE] [--coveralls_yaml COVERALLS_YAML] [--ignore-errors] [--merge_file MERGE_FILE] [--nogit] optional arguments: -h, --help show this help message and exit --coveralls_url COVERALLS_URL, -u COVERALLS_URL coveralls.io api url --base_dir BASE_DIR, -b BASE_DIR project root directory --data_file DATA_FILE, -d DATA_FILE coverage file name --config_file CONFIG_FILE, -c CONFIG_FILE coverage config file name --coveralls_yaml COVERALLS_YAML, -y COVERALLS_YAML coveralls yaml file name --ignore-errors, -i ignore errors while reading source files --merge_file MERGE_FILE, -m MERGE_FILE json file containing coverage data to be merged (for merging javascript coverage) --nogit do not gather git repo info