框架选择
python的测试工具大全:
https://wiki.python.org/moin/PythonTestingToolsTaxonomy
python主流的测试工具横向比较
http://docs.python-guide.org/en/latest/writing/tests/
http://pythontesting.net/test-podcast/
pytest的官方资料
http://wiki.zte.com.cn/pages/viewpage.action?pageId=38150854
CI的集成
普通的pytest安装是没有包含覆盖率的
pip install pytest
pytest覆盖率需要额外安装
pip install pytest-cov
这时,新增了py.test命令,这是原来pytest命令基础上封装的,新增了覆盖率功能。
例子示范:
py.test test_conf2bin.py --junit-xml=test_conf2bin_report.xml --cov-report=html --cov-config=.coveragerc --cov=./
- test_conf2bin.py是目标测试文件
- –junit-xml=test_conf2bin_report.xml是生成junit格式的test_conf2bin_report.xml
- –cov-report=html 输出html的报告
- –cov-config=.coveragerc 使用.coveragerc配置文件(py.test是基于coverage.py实现的,因此支持coverage.py的配置文件)
- –cov=./ 这个是必要的,如果没有这个,将无法输出html的报告
.coveragerc这个文件可以让py.test实现更多高级的功能,实现举例如下:
[run]
branch = True
[report]
include = conf2bin.py
[html]
directory = python_coverage_report
[report]
include = conf2bin.py
由于py.test会计算一个文件夹里的所有文件,如果只需要统计conf2bin.py这个文件的覆盖率,则可以这么写
[html]
directory = python_coverage_report
指的是html的输出文件夹
来源:https://blog.csdn.net/yyw794/article/details/73698408