Table of contents
4. Generate the URL of the test case
The previous blog introduced the installation and use of the pytest test framework. Now let’s talk about what test reports pytest can generate.
1.allure test report
2. Generate resultlog file
#!/usr/bin/python# -*- coding: UTF-8 -*-"""@author:chenshifeng@file:test_report.py@time:2021/01/27"""class TestReport: def test_one(self): x = "shifeng" assert "feng" in x def test_two(self): x = "hello" assert x == "hi"
Excuting an order:
pytest test_report.py --resultlog=./resultlog.txt
Specify the current path to generate resultlog.txt file, open the file, the content is as follows:
. reportdemo/test_report.py::TestReport::test_oneF reportdemo/test_report.py::TestReport::test_two self = <test_report.TestReport object at 0x7fd9c0a3eac0> def test_two(self): x = "hello" > assert x == "hi" E AssertionError: assert 'hello' == 'hi' E - hi E + hello test_report.py:16: AssertionError
3. Generate JunitXML file
Excuting an order:
pytest test_report.py --junitxml=./resultlog.xml
Also specify to generate the resultlog.xml file in the current directory, open the file as follows:
<?xml version="1.0" encoding="utf-8"?><testsuites> <testsuite errors="0" failures="1" hostname="chenshifengdeMacBook-Pro.local" name="pytest" skipped="0" tests="2" time="0.072" timestamp="2021-01-27T23:56:58.204464"> <testcase classname="reportdemo.test_report.TestReport" file="reportdemo/test_report.py" line="9" name="test_one" time="0.001"></testcase> <testcase classname="reportdemo.test_report.TestReport" file="reportdemo/test_report.py" line="13" name="test_two" time="0.002"> <failure message="AssertionError: assert 'hello' == 'hi' - hi + hello">self = <test_report.TestReport object at 0x7fa152b97790> def test_two(self): x = "hello" > assert x == "hi" E AssertionError: assert 'hello' == 'hi' E - hi E + hello test_report.py:16: AssertionError </failure> </testcase> </testsuite></testsuites>
What is the use of creating such an XML file? Mainly for the convenience of Jenkin or other continuous integration tools to read.
4. Generate the URL of the test case
Excuting an order:
pytest test_report.py --pastebin=all
Copy the session-log test report link generated at the end of the print result to the browser:
Of course, you can also choose to only show fail test cases
pytest test_class.py --pastebin=failed
5. Generate html test report
Install pytest-html via pip
pip install pytest-html
Execute the command in the current directory of the code file
pytest test_report.py --html=./report.html
Specify to generate a report.html file in the current directory and open the test file:
Summarize:
Thanks to everyone who read my article carefully! ! !
I personally sorted out some technical materials I have compiled in my software testing career in the past few years, including: e-books, resume modules, various job templates, interview books, self-study projects, etc. Everyone is welcome to leave a message in the comment area 333 to get it for free, don't miss it.