Automated testing framework Pytest (3) – custom allure test report

[After the pytest] test is completed, a good-looking test report can be generated through the third-party library. Come and learn an allure test report today.

1. Install allure-pytest

  1. Download, unzip, and configure the path.
    https://github.com/allure-framework/allure2/releases [_] _

Install the bin directory of the installation file into the [environment variable] path

D:\Program Files (x86)\allure-2.13.2\bin

Verify that the installation was successful:

allure --version

If pycharm verification fails, restart pycharm.

2. Add the address for generating the test report in the configuration

[pytest]  addopts = -vs  --alluredir  ./temptestpaths=./testcasepython_files=test_04.pypython_classes=Test*python_functions=testmarkers=smoke:smoke  case  usermanage : user - management - module www : test

3. Modify the main function

import os
import pytest
if __name__ == '__main__':    pytest.main()    os.system('allure generate ./temp -o ./report --clean')

4. Directly execute the main function to generate a report

5. Modify the main function every time the report is generated without replacing the previous one

import osimport time
import pytest

Uploading…Reupload canceled

2. Customize allure report

Modify the allure configuration. First open the installation directory, I installed in

D:\Program Files (x86)\allure-2.13.2

There are 4 directories inside:

bin: executable file

config: configuration file

lib: jar package

plugins: plugins

1. Logo customization

aModify config/allure.yaml and add a custom logo

- custom-logo-plugin

bModified pictures and styles

D:\Program Files (x86)\allure-2.13.2\plugins\custom-logo-plugin\static

/*.side-nav__brand {  background: url('custom-logo.svg') no-repeat left center !important;  margin-left: 10px;}*/
.side-nav__brand {  background: url('qq.png') no-repeat left center !important;  margin-left: 10px;  height: 90px;}

2. Function customization

Add project name, module name, title above the class

import allure
@allure.epic( "Project 1" )@allure.feature( "Module 1" ) class  Test04 : 
    @allure.story( "Use Case 1" ) @allure.title( "Successful Use Case" )     def  test_01 ( self ,wufantest ) : print( 'Test Baili's promise' +wufantest)
    @allure.story( "Case 1" ) @allure.title( "Failed Case" )     def  test_02 ( self ) : print( 'Test Nacolulu' )
    @allure.story( "Case 2" ) @allure.title( "Failed Case" )     def  test_03 ( self ) : print( 'Test Cai Wenji' )
You can see that the use cases in the test report have been automatically classified

3. We can also customize the priority of the use case through the following tags

  • BLOCKER: fatal bug

  • CRITICAL: Serious bug

  • NORMAL: normal

  • MINOR: Tips

  • TRIVIAL: Minor bug

@ allure . severity ( allure . severity_level . BLOCKER ) def test_01(self,wufantest): print( 'Test for compliance' +wufantest)

The priority display is shown in the following figure:

Learning resource sharing

Finally, I would like to thank everyone who has read my article carefully. Watching the rise and attention of fans all the way, there is always a need for ritual exchanges. Although it is not a very valuable thing, if you can use it, you can take it directly.

These materials should be the most comprehensive and complete preparation warehouse for friends who do [software testing]. This warehouse has also accompanied me through the most difficult journey. I hope it can also help you! Everything should be done as early as possible, especially in the technology industry, and the technical foundation must be improved. I hope to be helpful…….

If you don’t want to experience the feeling that you can’t find any information during self-study, no one answers your questions, and give up after a few days, you can join my QQ group below to discuss and exchange, and there are also various software testing materials and technical exchanges.

Leave a Comment

Your email address will not be published. Required fields are marked *