参考:https://blog.csdn.net/galen2016/article/details/105687512【Pytest】使用Allure测试报告

1.安装allure,配置环境变量。把allure的bin目录地址放在系统变量(右键我的电脑--属性--高级系统设置--环境变量--系统变量--path--编辑--新建--“你的allure的bin目录地址”--确定)path里。

allure下载地址:https://github.com/allure-framework/allure2/releases


2.参考代码:test_allure_demo.py
import allure

@allure.step("步骤1:打开百度")
def step_1():
    print("111")


@allure.step("步骤2:输入关键字")
def step_2():
    print("222")


@allure.feature("搜索")
class TestEditPage():
    @allure.story("百度搜索")
    def test_1(self):
        '''这是测试百度搜索'''
        step_1()
        step_2()
        print("百度一下,你就知道")

    @allure.story("谷歌搜索")
    def test_2(self):
        '''这是测试谷歌搜索'''
        assert 1 == 2, "搜索失败"

3.PyCharm的Terminal窗口(pycharm里右键就能看到)运行:
 pytest test_allure_demo.py --alluredir ./report

4.再执行执行:allure serve report,就可以看到报告了。

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐