Allure + pytest generate test reports

Summary:

python mainstream plug-in has three automatic test report: HTMLTestRunner, BeautifulReport and Allure. HTMLTestRunner is a relatively old report templates, the interface is not very good looking. BeautifulReport interface is very simple, looks very intuitive, is a relatively good report plug-ins. If you want to improve about your level, so that you become automated test reports on tall, then please select Allure.

 

Allure test report describes

Allure is a very lightweight and very flexible open source framework for test report generation. It supports most testing frameworks such as TestNG, Pytest, JUint and so on. It is simple to use, easy to integrate.

 

Pytest integrated framework Allure

Pytest Python unit testing framework is very convenient and easy to use. Strongly recommended to use this test framework for testing the work of a small partner in Python, compared with Python comes UnitTest easy to use too much. Later I will introduce Pytest testing framework with an entire article. Today we are mainly describes how to test report generation tool integrated into Pytest in Allure.


 

1.Allure download and install

Allure download the latest version: https://github.com/allure-framework/allure2/releases

After the download is complete, extract to pytest directory. Then set the environment variable, it simply is to enter \ allure-2.13.0 \ bin directory to perform allure.bat. cmd input allure viewing environment variable is set to succeed.

 

 

2. look-pytest

Download allure-pytest plug, used to generate the data needed for Allure test report.

pip3 install allure-pytest

 

 Case

Copy the code
# / usr / bin / env Python! 
# = UTF-8 Coding 
Import pytest 
Import Allure 
Import os 

@ pytest.fixture (scope = 'function') 
DEF the Login (): 
    Print ( "login") 
    yield 
    Print ( "login completed" ) 

@ allure.feature ( 'Add to cart') 
DEF TEST_1 (the Login): 
    '' 'the Apple Add to cart' '' 
    Print ( "test Case 1") 

@ allure.feature ( 'Add to cart') 
DEF test_2 (): 
    '' 'the orange Add to cart' '' 
    Print ( "test Case 2") 

IF __name__ == "__ main__": 
    # pytest unit test execution to generate data required for reporting the presence of Allure / temp directory 
    pytest.main ( [ '--alluredir', './temp'])  
    # Run allure generate./ Temp -o ./report --clean, generate test reports
    the os.system ( ' allure generate ./temp -o ./report --clean') 
Copy the code

@allure decorator in some of the functions:

@ allure.feature: define a function to be tested, the test product demand point
@ allure.story: used to define a user function tested scenarios, i.e. the point subfunction
@ allure.step: for a test case, divided into several steps in the report output
allure.attach: for inputting additional information to the test report, usually some test data

 

3, generate test reports Allure

3.1 test script execution

After the test script adds Allure features needed to test the results of Mr. Allure report data required when performing the test. Py.test when performing the test, designated -alluredir save options and test data directory can be:

  $ py.test test/ --alluredir ./result/

./result/ save the results of this test data. Further, the features specified may also be performed or executed as part of the test case stories, such as the implementation of 'shopping cart functionality' under 'Add to Shopping Cart "test functions of:

$ Py.test test / --allure_features = 'shopping cart functionality' --allure_stories = 'Add to Cart'

  After the run is completed will produce xml report in the specified directory

3.2 test report generation

After installation, the following test data in order to generate a test report ./result/ directory:

 $ allure generate ./result/ -o ./report/ --clean

 

In this directory ./report/ generates the Allure of the test report. -clean aim is to empty the test report directory, and then generate a new test report.

 

 

3.3 Open test report

Guess you like

Origin www.cnblogs.com/kuaileya/p/12035007.html