If you want to learn Pytest from scratch, you can check out this series of articles!
https://www.cnblogs.com/poloyy/category/1690628.html
Foreword
The characteristics of two allures were introduced earlier
- @ allure.step () decorator: you can set test steps to make the execution process of test cases more detailed
- allure.attach () function: you can set the attachments that need to be displayed in the allure report, which contains multiple types, you can view the supported types through allure.attachment_type
In this article, we mainly explain two other features, which can increase the readability of the report!
- @allure.description()
- @allure.title()
Their usage is very similar, but their functions are different
@allure.description()
effect
You can add enough detailed test case descriptions for the management to check. Hahaha
There are three syntax formats
- @allure.description(str)
- Add "" "" "" under the test case function declaration
- @ allure.description_html (str): equivalent to passing a string of HTML code, similar to passing HTML in allure.attach ()
Note: The effect and effect of method one and method two are the same, whichever is more convenient
#!/usr/bin/env python # -*- coding: utf-8 -*- """ __title__ = __Time__ = 2020-04-18 15:24 __Author__ = Little pineapple test notes __Blog__ = https://www.cnblogs.com/poloyy/ """ import allure import allure # 方法一 @ allure.description ( "" " This is a @ allure.description decorator No special use """) def test_description_from_decorator(): assert 42 == int(6 * 7) # 方式二 def test_unicode_in_docstring_description(): """ Of course, writing in the next line of the method declaration is also a way to add description """ assert 42 == int(6 * 7) # 方法三 @ allure.description_html ( "" " <h1>Test with some complicated html description</h1> <table style="width:100%"> <tr> <th>Firstname</th> <th>Lastname</th> </tr> <tr align="center"> <td>William</td> <td>Smith</td> </table> """) def test_html_description(): assert True
operation result
Allure report of way one
Allure report of way two
Allure report of way three
@allure.title()
effect
- Make the title of the test case more readable, after all, we can write it in Chinese
- Support placeholder to pass keyword parameters
Concrete chestnut one
#!/usr/bin/env python # -*- coding: utf-8 -*- """ __title__ = __Time__ = 2020-04-18 16:09 __Author__ = Little pineapple test notes __Blog__ = https://www.cnblogs.com/poloyy/ """ import pytest, allure @ allure.title ( " Pre-operation: login " ) @pytest.fixture def test_loginss(request): params = request.param name = params["username"] pwd = params["pwd"] allure.attach (f " This is the parameter passed by the test case {params} " ) print (name, pwd, params) yield name, pwd @ allure.title ( " Successful login, the test data is: {test_loginss} " ) @pytest.mark.parametrize("test_loginss", [ {"username": "name1", "pwd": "pwd1"}, {"username": "name2", "pwd": "pwd2"}], indirect=True) def test_success_login(test_loginss): name, pwd = test_loginss allure.attach (f " Account {name}, password {pwd} " )
Run results, view allure report
This is a chestnut that is completed by combining multiple previously learned methods at a time, and it has been specifically marked!
Two concrete chestnuts
@ allure.title ( " Multiple parameters {name}, {phone}, {age} " ) @pytest.mark.parametrize("name,phone,age", [ (1, 2, 3), (4, 5, 6), (7, 8, 9) ]) def test_test_test(name, phone, age): print(name, phone, age)
Run results, view allure report
to sum up
If @ allure.title () is not added , the title of the test case is the function name by default, which is not readable. After all, we are Chinese, and it is still necessary to display the Chinese title ~ so the wall crack is recommended to everyone. Go!