• 【pytest】生成测试报告


      0. 脚本: 

     fixture/test_fixtures_02.py

    1. # 功能函数
    2. import pytest
    3. def multiply(a, b):
    4. return a * b
    5. class TestMultiply:
    6. # =====fixtures========
    7. @classmethod
    8. def setup_class(cls):
    9. print("setup_class=========>")
    10. @classmethod
    11. def teardown_class(cls):
    12. print("teardown_class=========>")
    13. def setup_method(self, method):
    14. print("setup_method----->>")
    15. def teardown_method(self, method):
    16. print("teardown_method-->>")
    17. def setup(self):
    18. print("setup----->")
    19. def teardown(self):
    20. print("teardown-->")
    21. # =====测试用例========
    22. def test_numbers_5_6(self):
    23. print('test_numbers_5_6')
    24. assert multiply(5, 6) == 30
    25. def test_strings_b_2(self):
    26. print('test_strings_b_2')
    27. assert multiply('b', 2) == 'bb'

       1.生成 xml 报告 

    main.py

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

    报告: 

    1. "1.0" encoding="utf-8"?>
    2. <testsuites>
    3. <testsuite name="pytest" errors="0" failures="0" skipped="0" tests="6" time="0.231" timestamp="2023-09-18T06:57:21.230110" hostname="WIN-9AMNN7ECA5T">
    4. <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" />
    5. <testcase classname="fixture.test_fixtures_02.TestMultiply" name="test_strings_b_2" time="0.003" />
    6. testsuite>
    7. testsuites>

    方便处理成自己需要报告 

     2.生成在线报告

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

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

    打开View paste L2HQ

  • 相关阅读:
    优先级队列(堆)
    Knife4j_接口概述、常用注解详解、搭建swagger项目、功能概述
    HDFS编程实践-从HDFS中下载指定文件到本地
    【SpringMVC】基础部分
    Netty线程模型
    学习笔记——网络管理与运维——SNMP(基本配置)
    Scala的简单语法介绍
    【Spring Boot 使用记录】kafka自动配置和自定义配置及消费者
    程序员的数学课01 从计数开始,程序员必知必会的数制转换法
    基于HKELM混合核极限学习机多输出回归预测 (多输入多输出) Matlab代码
  • 原文地址:https://blog.csdn.net/oDianZi1234567/article/details/132962518