【pytest】生成测试报告

0. 脚本:

fixture/test_fixtures_02.py

复制代码
# 功能函数
import pytest


def multiply(a, b):
    return a * b


class TestMultiply:
    # =====fixtures========
    @classmethod
    def setup_class(cls):
        print("setup_class=========>")

    @classmethod
    def teardown_class(cls):
        print("teardown_class=========>")

    def setup_method(self, method):
        print("setup_method----->>")

    def teardown_method(self, method):
        print("teardown_method-->>")

    def setup(self):
        print("setup----->")

    def teardown(self):
        print("teardown-->")

    # =====测试用例========
    def test_numbers_5_6(self):
        print('test_numbers_5_6')
        assert multiply(5, 6) == 30

    def test_strings_b_2(self):
        print('test_strings_b_2')
        assert multiply('b', 2) == 'bb'

1.生成 xml 报告

main.py

复制代码
import pytest

if __name__=='__main__':
    #pytest.main(['-s','./fixture'])
    pytest.main(['-v', './fixture','--junit-xml=./report/log.xml'])

报告:

XML 复制代码
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite name="pytest" errors="0" failures="0" skipped="0" tests="6" time="0.231" timestamp="2023-09-18T06:57:21.230110" hostname="WIN-9AMNN7ECA5T">
<testcase classname="fixture.test_fixtures_01" name="test_mult_3_4" time="0.003" /><testcase classname="fixture.test_fixtures_01" name="test_mult_a_4" time="0.004" /><testcase classname="fixture.test_fixtures_011" name="test_multiply_3_4" time="0.003" /><testcase classname="fixture.test_fixtures_011" name="test_multiply_a_3" time="0.003" /><testcase classname="fixture.test_fixtures_02.TestMultiply" name="test_numbers_5_6" time="0.003" />
<testcase classname="fixture.test_fixtures_02.TestMultiply" name="test_strings_b_2" time="0.003" />
</testsuite>
</testsuites>

方便处理成自己需要报告

2.生成在线报告

--pastebin=all 生成一个 session-log 链接浏览器打开

XML 复制代码
import pytest

if __name__=='__main__':
    pytest.main(['-s','./fixture'])
    #pytest.main(['-v', './fixture','--junit-xml=./report/log.xml'])
    pytest.main(['-v', './fixture', '--pastebin=all'])
XML 复制代码
======================== 6 passed, 1 warning in 0.14s =========================
==================== Sending information to Paste Service =====================
pastebin session-log: https://bpa.st/show/GFZQ

打开View paste L2HQ

相关推荐
User_芊芊君子几秒前
Python+Agent入门实战:0基础搭建可复用AI智能体
开发语言·人工智能·python
迷你可可小生几秒前
图像视觉面经学习(一)
图像处理·人工智能·python·学习
平安的平安1 分钟前
用 Python 玩转 AI 绘图:Stable Diffusion 本地部署指南
人工智能·python·stable diffusion
开开心心就好1 分钟前
操作简单的ISO文件编辑转换工具
java·前端·科技·edge·pdf·安全威胁分析·ddos
盐水冰2 分钟前
【HTML】(1)- 演示&标记语言
前端·html
还是大剑师兰特3 分钟前
Pinia介绍及Vue3配置示例
前端·javascript·vue.js
志栋智能4 分钟前
超自动化巡检:洞察未知隐患,助您事前不出事
大数据·运维·网络·数据库·自动化
李少兄8 分钟前
网页应用化部署指南:基于 Edge 浏览器创建桌面快捷方式
前端·edge
IT_陈寒8 分钟前
Python的异步陷阱:我竟然被await坑了一整天
前端·人工智能·后端
光影少年9 分钟前
Android和iOS原生开发的基础知识对RN开发的重要性,RN打包发布时原生端需要做哪些配置?
android·前端·react native·react.js·ios