[371]python测试框架(pytest)

框架选择

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值