【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

相关推荐
Amagi.几秒前
Redis的内存淘汰策略
数据库·redis·mybatis
企业管理8MSaaS3 分钟前
了解CRM销售自动化:类型、优势、策略和工具
运维·自动化
hai4117419626 分钟前
mysql 与postgresql 的区别(gpt4)
数据库·mysql·postgresql
Freak嵌入式10 分钟前
全网最适合入门的面向对象编程教程:50 Python函数方法与接口-接口和抽象基类
java·开发语言·数据结构·python·接口·抽象基类
知识分享小能手16 分钟前
mysql学习教程,从入门到精通,SQL 删除数据(DELETE 语句)(19)
大数据·开发语言·数据库·sql·学习·mysql·数据开发
crownyouyou21 分钟前
最简单的一文安装Pytorch+CUDA
人工智能·pytorch·python
&白帝&24 分钟前
uniapp中使用picker-view选择时间
前端·uni-app
鸽芷咕24 分钟前
【Python报错已解决】libpng warning: iccp: known incorrect sRGB profile
开发语言·python·机器学习·bug
WenGyyyL24 分钟前
变脸大师:基于OpenCV与Dlib的人脸换脸技术实现
人工智能·python·opencv
白总Server30 分钟前
MongoDB解说
开发语言·数据库·后端·mongodb·golang·rust·php