42-pytest-添加Junit报告

Posted 爱学习de测试小白

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了42-pytest-添加Junit报告相关的知识,希望对你有一定的参考价值。

添加Junit报告


前言

  • 本篇来学习pytest中如何生成Junit报告

生成Junit报告

  • 使用 --junit-xml 参数执行报告生成路径
# -*-coding:utf-8一*-
# @Time:2022/10/15
# @Author : 大海

import os


def test_str():
    """断言字符串"""
    value = 'hello'
    assert 'h' in value


if __name__ == '__main__':
    # --junit-xml 报告路径 
    os.system('pytest test_73.py --junit-xml=./report.xml')

  • 查看报告

修改Junit报告

修改报告name

  • pytest.ini 中添加 junit_suite_name配置
[pytest]

junit_suite_name=test_str
# -*-coding:utf-8一*-
# @Time:2022/10/15
# @Author : 大海

import os


def test_str():
    """断言字符串"""
    value = 'hello'
    assert 'h' in value


if __name__ == '__main__':
    # --junit-xml 报告路径 
    os.system('pytest test_73.py --junit-xml=./report.xml')
  • 查看报告

修改报告中的class属性

  • 添加–junit-prefix 命令行参数
# -*-coding:utf-8一*-
# @Time:2022/10/15
# @Author: WZ

import os


def test_str():
    """断言字符串"""
    value = 'hello'
    assert 'h' in value


if __name__ == '__main__':
    # --junit-xml 报告路径  --junit-prefix 报告中的class属性
    os.system('pytest test_73.py --junit-xml=./report.xml --junit-prefix=DH')
  • 查看报告

以上是关于42-pytest-添加Junit报告的主要内容,如果未能解决你的问题,请参考以下文章