Pytest allure 生成测试报告


1、之前用到 Pytest 中的插件 --html 生成报告,今天我们看下 Pytest 结合 allure 的使用

import pytest
import os

class TestDemo():
    def test_01(self):
        assert 1 == 1

    def test_02(self):
        assert 1 == 0

    def test_03(self):
        print("hello world")

if __name__ == '__main__':
    pytest.main(["-s", "./test_demo1.py", "--alluredir=./result", "--clean-alluredir"])
    """
    --alluredir=./result    -->     指定运行后生成 json 格式的结果文件目录
    --clean-alluredir       -->     指定每次运行后情况 json 文件目录,防止文件累积
    """
    os.system("allure generate ./result -c -o ./report")
    """
    allure generate         -->     allure 生成报告的命令,固定写法
    ./result                -->     获取报告数据的 json 文件目录
    -c                      -->     每次执行后清空报告目录
    -o                      -->     输出报告命令
    ./report                -->     报告存放目录
    """