标签:lang == demo 测试案例 object python assert install highlight
pytest 生成报告,需要提前安装插件
pip install pytest-html
使用方式:
在运行时使用--html=report.html (report就是生成html的文件名)
eg:pytest test_rundemo.py --html=reportdemo.html
测试案例:做了一个计算器,然后断言一个失败
class Calc(object):
@classmethod
def add(cls, x, y, *d):
# 加法计算
result = x + y
for i in d:
result += i
return result
@classmethod
def sub(cls, x, y, *d):
# 减法计算
result = x - y
for i in d:
result -= i
return result
@classmethod
def mul(cls, x, y, *d):
# 乘法计算
result = x * y
for i in d:
result *= i
return result
@staticmethod
def div(x, y, *d):
# 除法计算
if y != 0:
result = x / y
else:
return -1
for i in d:
if i != 0:
result /= i
else:
return -1
return result
def test_add():
assert Calc.add(1, 2, 3) == 60 #断言失败
def test_sub():
assert Calc.sub(100, 20, 30) == 50
控制台运行效果

在项目统计目录生成报告文件


标签:lang == demo 测试案例 object python assert install highlight
原文地址:https://www.cnblogs.com/chongyou/p/12513963.html