Interface test Pytest test report

When the pytest command line is running, you can directly view the output results in the console, but such results are not intuitive and are not easy to save for subsequent analysis and sharing. Such as pytest -s -q test_xx.pythe output result.


Pytest's report output method

  • Report file in JunitXml format:pytest --junitxml=path

  • report file in resultlog text format: pytest --resultlog=path( not commonly used, expected to be removed in 4.0 )

  • Report file in url format, generate a url for each use case or specified use case: pytest --pastebin=all, only output the failed ones, you can replace all with failed

  • Third-party plugin: pytest-html


Pytest test report example


1. Test report in JunitXML format

  • Reports in JunitXML format are appended to the pytest command with --junitxml=path.

  • Run the use cases in the test set:pytest -q --tb=no --junitxml='E:\python_interface_test\results\makejunitstyle.xml'

  • --tb=noDo not output traceback information

  • Look at the picture: 4 use cases failed, 25 use cases passed, 1 use case was xfailed, and 1 use case was wrong


    junit.png

  • View the generated report, the report path and name are set after --junitxml=

  • Look at the picture:
    1), the information in the testsuit includes: total running time, the total number of use cases, the number of use cases that were skipped or unsuccessfully executed;
    2), the information in the testcase includes: the running time of the case, the name of the case, the row where the case is located 3) If the
    case has output information or error information, it will also be displayed in the corresponding element, see the use case with output or error.


xmlreport.png


2. Test report in resultlog text format (expected to be removed in 4.0)

  • Run the command:pytest -q --tb=no --resultlog='E:\python_interface_test\results\resultlog2.txt'



resultlog.png


  • View the results: (I don't understand it at all, don't pay attention to this generation method)


    logreport.png


3. Test report in url format

  • The report in url format is to send the test results to the pastebin server, and after the execution of the use case is completed, a url address is generated

  • 运行命令:pytest --pastebin=all,如果只想看失败的信息把all换成failed

    url.png


  • 查看结果:输出信息和控制台中的traceback一样,只是保存在了服务器上,看起来还是比较乱


    urlreport.png


4、pytest-html第三方插件生成的测试报告

  • 秉持拿来主义的精神,这个报告应该会好看一点


4.1.安装pytest-html

pytest插件的安装和卸载方式为:

pip install pytest-NAME
pip uninstall pytest-NAME

so,安装pytest-html:

python -m pip install pytest-html

4.2.pytest-html的使用

pytest-html顾名思义,生成的报告格式为html的。

  • 运行命令:pytest -q --tb=no --html=E:\python_interface_test\results\makehtml.html

html.png

  • 查看结果:结果中分为3部分,Environment、Summary、Results;
    1)、在html报告中会有报告生成日期及采用的pytest-html版本;
    2)、Environment:记录了运行的环境信息;
    3)、Summary:描述了运行用例数、时间及用例的状态;
    4)、Results:记录了每个用例的执行状态、用例名称及路径、执行时间;(ps:执行时间只精确到2位小数,所以好多用例的时间都为0)


    htmlreport.png


总结

从上面的介绍中看出,JunitXML和pytest-html的可读性和可分析性更好。

  • JunitXML可用于持续集成,格式为xml;

  • pytest-html界面美观,执行信息及结果信息全面。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324501813&siteId=291194637