我们会在持续集成日志中展示测试结果
结果展示文件需要使用测试脚本(命令)生成 junit 格式的 XML 文件,该文件路径由系统环境变量 `TEST_RESULT` 指定。例:
nosetests test.py --with-xunit --xunit-file=$TEST_DIR/result.xml
结果:
<?xml version="1.0" encoding="utf-8"?>
<testsuite name="nosetests" tests="1" errors="0" failures="0" skip="0">
<testcase classname="test.TestSuite" name="test" time="0.033"></testcase>
</testsuite>
覆盖测试文件需要使用测试脚本(命令)生成 一个 xml 格式的 coverage 报告,该文件路径由系统环境变量 `TEST_COVERAGE` 指定。例:
coverage xml -o $TEST_DIR/coverage.xml test.py
结果:
<?xml version="1.0" ?>
<coverage branch-rate="0.5" line-rate="1" timestamp="1445931368445" version="4.0.1">
<!-- Generated by coverage.py: https://coverage.readthedocs.org -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/f0366e5e2cf18f111cbd61fc34ef720a6584ba02/htdocs/xml/coverage-03.dtd -->
<sources>
<source>/daocloud/builder/src</source>
</sources>
<packages>
<package branch-rate="0.5" complexity="0" line-rate="1" name=".">
<classes>
<class branch-rate="0.5" complexity="0" filename="test.py" line-rate="1" name="test.py">
<methods/>
<lines>
<line hits="1" number="1"/>
<line hits="1" number="2"/>
<line hits="1" number="4"/>
<line hits="1" number="5"/>
<line hits="1" number="6"/>
<line hits="1" number="7"/>
<line hits="1" number="8"/>
<line hits="1" number="9"/>
<line hits="1" number="11"/>
<line hits="1" number="12"/>
<line branch="true" condition-coverage="50% (1/2)" hits="1" missing-branches="exit" number="14"/>
<line hits="1" number="15"/>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
代码参见 GitHub 上的 样例程序
image: daocloud/ci-python:2.7
services:
- mysql
env:
- MYSQL_USERNAME="root"
- MYSQL_PASSWORD=""
- MYSQL_INSTANCE_NAME="test"
script:
- pip install -r requirements.txt
- nosetests test.py --with-xunit --xunit-file=$TEST_RESULT
- coverage run --branch test.py
- coverage xml -o $TEST_COVERAGE test.py
- cat $TEST_RESULT
- cat $TEST_COVERAGE