pytest测试框架的简单应用
1.安装pytest
命令行或者终端中输入 pip install pytest
2.安装allure-pytest
命令行或者终端中输入 pip install allure-pytest
3.安装allure
https://github.com/allure-framework/allure2/releases
class test_demo:
def __init__(self):
self.a=0
self.b=0
def add_test(self,a,b):
self.a=a
self.b=b
return self.a+self.b
def ride_test(self,a,b):
self.a = a
self.b = b
return self.a*self.b
import pytest
import allure
from testdata import test_demo
mcc = test_demo()
class TestCase(object):
@allure.step("测试加法函数")
def test01(self):
result = mcc.add_test(1, 3)
assert result == 5
@allure.step("测试乘法函数")
def test02(self):
result = mcc.ride_test(2, 3)
assert result == 6
if __name__ == '__main__':
pytest.main()
>pytest test_testpy.py --alluredir ./report/result #执行用例,并在当前./report/result目录下生成json文件
>allure serve report/result #启动服务,读取目录下的json文件,呈现可视化测试报告