pytest combined with allure-pytest plug-in to generate allure test report

Allure Test Report Overview

1. The principle of Allure report generation

The Allure report is generated based on the standard xUnit result output and supplementary data is added. The report generation is based on the following two steps.

  • During test execution, a small library called Adapter is wired into the test framework and saves all test execution information into XML files. For most popular testing frameworks in programming languages ​​(such as pytest in python, jUnit in Java, etc.), Allure provides Adapters by default.

  • After getting the XML files, Allure converts these XML files into HTML reports. This step can be achieved through the Allure plug-in of the continuous integration system, or command line commands.

2. Allure report features

The reason why the Allure report is highly praised by developers, testers, and even managers is because it has the following obvious characteristics.

  • From a development/QA perspective, Allure reports can shorten the lifecycle of common defects.

Test failures can be divided into bugs and broken (Broken) tests, and logs, steps, fixtures, attachments, time, history, and integration with TMS and Bug tracking systems can be configured to facilitate linking Tasks with responsible Task developers Binding with testers, so that developers and testers can grasp all the information at the first time.

  • From a manager's point of view, Allure provides a clear "big picture" view.

Including which functions are covered by this test, which case the bug is found in, and the overall test case, the execution time of a single test case, etc.

The image below is a rough preview of an Allure test report.

 2. Configure allure-pytest

  1. Download, decompress, configure path path

    http://github.com/allure-framework/allure2/releases

    path path configuration: allure installation directory

    Verify: allure --version

    Question: dos can be verified but pycharm verification fails, what to do, restart pycharm

  2. Generate ad hoc reports in json format

    --alluredir ./temp

3. Generate allure report (parameter explanation)

allure generate 命令固定的

./temp 临时的json格式报告的路径

-o 输出output

./report 生成的allure报告的路径

--clean 清空原来的报告

ps: You can write --alluredir ./temp into the pytest.ini file as follows

[pytest]
addopts = -vs --alluredir ./temp
testpaths = ./testcase
python_files = test_*.py
python_classes = Test*
python_functions = test
markers =
    somke:冒烟用例
    usermanage:用户管理模块

Run test cases in run.py

if __name__ == '__main__':
   
    pytest.main(['-vs','./testcase/ceshiren'])    #运行什么文件?
    # os.system('allure generate ./temp -o ./report --clean')  #生成allure报告

 

The icon on the left of the allure report style is my custom 

Allure is still very flexible. You can modify the configuration file by yourself and choose to add some things, such as screenshots or the environment, etc.

 

Guess you like

Origin blog.csdn.net/wuyomhchang/article/details/127561600