directory
- Allure Test Report
- Pytest and allure(/əˈlo͝or/
- Customizing Allure Reports
Allure Test Report
There are many cool testing frameworks for different programming languages. Unfortunately, only a few of them provide a good representation of the test execution output. The Qameta software testing team is working on Allure, an open source framework designed to create test execution reports that are clear to everyone on the team.
Reference article:
The Allure of official document: https://docs.qameta.io/allure/
Blog.csdn.net/liuchunming…
Pytest and allure (/ goes ˈ lo ͝ or /
) the spark in the middle
-
Install allure: github.com/allure-fram…
- Decompress the file and add it to the environment variables of the corresponding OPERATING system
-
PIP install allure- Pytest
-
Pytest — Alluredir =./ Report /allure_report_01
-
Check out the actual report (displayed in the browser, which enables a local Web service) : Allure serve./ Report /allure_report_01
-
Generate test reports (empty the test report directory before each build) : Allure generate./report/allure_report_01/ -o./report01/ –clean
-
Matters needing attention
If you run pyTest — AllureDir = Report, you will create a report directory directly under the current directory and run pyTest.
Customizing Allure Reports
-
Add a description to the test method in the Allure report: Just add “”” “Described “”” “under the test function/method.
def test_sum(self) : """ This will be shown in the Allure report. """ # assert makes assertions assert 1= =2 Copy the code
-
Test step description: Add @allure. Step (‘ step description ‘) content before the test method
#! /usr/bin/env/python3 # -*- coding:utf-8 -*- """ @project: pytest_study @author: zy7y @file: test_09.py @ide: PyCharm @time: 2020/7/27 """ import allure import pytest @allure.step('First step') def passing_step() : pass @allure.step('Step two') def step_with_nested_steps() : nested_step() @allure.step('Step 2, step 1') def nested_step() : nested_step_with_arguments(1.'abc') @allure.step('Step 2. Step 2') def nested_step_with_arguments(arg1, arg2) : pass def test_with_imported_step() : passing_step() def test_with_nested_steps() : passing_step() step_with_nested_steps() Copy the code
A step can have a description line that supports placeholders for positional and keyword arguments that are passed. The default arguments for keyword arguments will also be captured.
import allure @allure.step('Placeholder in test step title, first parameter: "{0}", second parameter keyword: "{key}"') def step_with_title_placeholders(arg1, key=None) : pass def test_steps_with_placeholders() : step_with_title_placeholders(1, key='something') step_with_title_placeholders(2) step_with_title_placeholders(3.'anything') Copy the code
-
Ids test case title: The contents of each use case IDS keyword parameter will be populated in the Allure report
@pytest.mark.parametrize('username, password, expect', [('admin'.'123456'.'Login successful'), ('admin'.'111111'.'Password error')], ids=["Normal Login Test Case title"."Incorrect Password Login Test Case"]) def test_login(username, password, expect) : if username == 'admin' and password == '123456': assert expect == 'Login successful' else: assert expect == 'Password error' Copy the code
-
Add an attachment to a test case/function/method of Allure :arllure.attcah(body, name, attachment_type, extension) or add a local attachment to allure. attachment_type, extension)
body
– Indicates the file content to be writtenname
– File nameattachment_type
– File typeallure.attachment_type
extension
– File name extensionsource
– File path
import allure import pytest @pytest.fixture def attach_file_in_module_scope_fixture_with_finalizer(request) : # add a TXT file called file_name and hold the allure text attachment allure.attach('Allure text Attachment content'.'file_name', allure.attachment_type.TEXT) def test_multiple_attachments(attach_file_in_module_scope_fixture_with_finalizer) : # locally upload an image file to Allure, allure.attach.file('./Snipaste_2020-07-27_23-29-48.png', name='special allure', attachment_type=allure.attachment_type.PNG) allure.attach('<head></head><body> a page </body>'.'HTML attachment', allure.attachment_type.HTML) Copy the code
-
Custom test title(test how functions are displayed in allure) content: @attraction.title ()
@allure.title('Test title: Test open blog') @allure.step('3. Hit Enter ') def test_open_blog(browse_driver) : browse_driver.find_element_by_id('su').click() # document.dynamic.title (' After successfully completing the test, the title is replaced with this line. ') Copy the code
-
Add a link :@allure. Link or @allure. Issue or @allure. Testcase
# display link @allure.link('https://www.baidu.com/') def test_with_link() : pass @allure.link('https://www.youtube.com/watch?v=Su5p2TqZxKU', name='allure. Link implements, passing a URL, a name') def test_with_named_link() : pass # can be used to put zen Path bug address, its icon is a bug is good @allure.issue('https://www.baidu.com'.'This is the icon that shows up, click on it to access the link') def test_with_issue_link() : pass The title of the test case is displayed below the link bar. Click to jump to it @allure.testcase(TEST_CASE_LINK, 'Test Case Title') def test_with_testcase_link() : pass Copy the code
-
Execute in groups by tag :@allure. Feature and @allure. Story
@allure.story('epic_1') def test_with_epic_1() : pass @allure.story('story_1') def test_with_story_1() : pass @allure.story('story_2') def test_with_story_2() : pass @allure.feature('feature_2') @allure.story('story_2') def test_with_story_2_and_feature_2() : pass # pyTest test_09.py --allure-stories story_1,story_2 # pytest test_09.py --allure-features feature2 --allure-stories story2 Copy the code
-
Group by severity (priority) :@allure. Severity
# test.py import allure @allure.severity('blocker') def test_with_no_severity_label() : pass @allure.severity(allure.severity_level.TRIVIAL) def test_with_trivial_severity() : pass @allure.severity(allure.severity_level.NORMAL) def test_with_normal_severity() : pass @allure.severity(allure.severity_level.NORMAL) class TestClassWithNormalSeverity(object) : def test_inside_the_normal_severity_test_class(self) : pass @allure.severity(allure.severity_level.CRITICAL) def test_inside_the_normal_severity_test_class_with_overriding_critical_severity(self) : pass NORML/CRITICAL methods/classes/functions will be executed # pytest tests.py --allure-severities normal,critical Copy the code
Description: BLOCKER = 'BLOCKER' System blocks corresponding bug priority: CRITICAL = 'CRITICAL' CRITICAL - NORMAL = 'NORMAL' NORMAL - Third from bottom to bottom to handle MINOR = 'MINOR' usability issue TRIVIAL = 'TRIVIAL' usability issueCopy the code
The severity and priority of the bug can be found here: blog.sina.com.cn/s/blog_4adc…