[pytest] Generate test report

  0. Screenplay: 

 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. Generate xml report 

main.py

import pytest

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

Report: 

<?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>

Conveniently process reports according to your own needs 

 2. Generate online reports

--pastebin=all generates a session-log link and opens it in the browser

import pytest

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

Open View paste L2HQ

Guess you like

Origin blog.csdn.net/oDianZi1234567/article/details/132962518