allure is a plug-in that can generate visual test reports. It has the following characteristics:
- allure is a lightweight, flexible and multilingual test reporting tool
- Multi platform and luxurious report framework;
- Can be dev/qa Provide detailed test report, test steps and log;
- It can also provide high-level statistical reports for the management;
- Developed in Java language, supporting pytest, JaveScript, PHP, ruby, etc
- Can be integrated into Jenkins
The following is a novice demo tutorial for the integration of allure plug-in and pytest, which is a tutorial reference allure official documentation.
1. Install alure
The following is the installation command of mac system. For other systems, please Click here View installation method
brew install allure
2. Install the allure pytest plug-in
This plug-in is used to integrate with pytest and collect the execution of pytest runtime case.
The installation command is pip install allure-pytest
$ pip install allure-pytest
3. Write case and configure environment
I've created one here called allure_test folder. There are only two files and one folder under the folder, and one of the two files is empty__ init__.py file, and the other is test_allure_demo.py. The allure result folder is used to store test reports. There are three necessary configuration files. The contents of each file are described below.
allure_test/ ├── __init__.py # Empty file ├── test_aullure_demo.py # test case file └── allure-result # Test results folder ├── categories.json ├── environment.properties └── environment.xml
__init__.py
Empty
test_aullure_demo.py
This is the case of pytest execution. You can see that there are four cases, one successful case, one skipped case and two failed cases.
import pytest def test_success(): """this test succeeds""" assert True def test_failure(): """this test fails""" assert False def test_skip(): """this test is skipped""" pytest.skip('for a reason!') def test_broken(): raise Exception('oops')
Allure result folder
The three files in this folder are environment configuration files. Put these three configuration files in which folder you want to generate test reports. At present, the role of each configuration file is not very clear. The following is the content of each configuration file. You can copy it directly without modification.
categories.json
[ { "name": "Ignored tests", "matchedStatuses": [ "skipped" ] }, { "name": "Infrastructure problems", "matchedStatuses": [ "broken", "failed" ], "messageRegex": ".*bye-bye.*" }, { "name": "Outdated tests", "matchedStatuses": [ "broken" ], "traceRegex": ".*FileNotFoundException.*" }, { "name": "Product defects", "matchedStatuses": [ "failed" ] }, { "name": "Test defects", "matchedStatuses": [ "broken" ] } ]
environment.properties
Browser=Chrome Browser.Version=63.0 Stand=Production
environment.xml
<environment> <parameter> <key>Browser</key> <value>Chrome</value> </parameter> <parameter> <key>Browser.Version</key> <value>63.0</value> </parameter> <parameter> <key>Stand</key> <value>Production</value> </parameter> </environment>
4. Run the case and set the test report saving path
The current terminal enters allure_ Under the test path, execute the following command. pytest executes case with -- allouredir Parameter indicates the path to save the test report.
pytest --alluredir=./allure-result
The following is the running result. One case succeeded, two cases failed and one case skipped. As we expected.
5. Generate online html visualization Report
Use allure to generate online html test reports. Continue to execute allure serve. / allure result on the current terminal
allure serve ./allure-result
If you see the following execution results, the execution is successful
Then we will automatically jump to the browser and display our test report in a new tab.
Click the navigation bar on the left to see the execution of each case
The above contents are for reference allure official documentation , a few references: Introduction and use of python allure (under continuous update)