当前位置:网站首页>Introduction and use of pytest fixture, confitest and mark
Introduction and use of pytest fixture, confitest and mark
2022-06-22 00:43:00 【Don't ask me y】
Preface
stay b Learning videos found on the website , The title is pytest Frame learning , Followed for a period of time , When writing test cases, I found that the following parentheses of the class say unittest.Testcase, Now I know pytest yes unittest Upgraded version , What are the specific differences? I will add them after my follow-up study
1、pytest Use under the frame fixture,unittest Next use setup、teardown( I'm not sure if this is right )
2、fixture Introduce
fixture Defines the steps and data that make up the test preparation phase
2.1 fixture Fixed writing :
@pytest.fixture(scope = 'function',autouse = ‘True')
def my_fixture():
print("a")
perhaps
@pytest.fixture(scope = 'function',autouse = ‘True')
def my_fixture(request):
print(' In front of ’)
# Add ,yield It acts as a dividing line , Separate front and rear
yiled request.pram //yield and return It means to return , however yield You can continue to write code later ,return Not in the back
print(‘ After ’)
2.2 fixture Marked functions , Cannot follow test function 、 Put the test classes together , I put fixture The method of marking is written as test_ start , It's not right
2.3 fixture Use
- The marked function is passed into the test case as a parameter
@pytest.fixture()
def my_fixture():
print ("a")
def test_01(my_fixture):
print(" Use fixture One way “)
- Use decorators :
@pytest.mark.usefixtures(" ")
3、conftest
- It's all fixture
- fixture It can be shared externally - All use cases share
- priority : Nearby principle
- You can create... Hierarchically
- It can't be put together with the test case ( Can't use test_) Name the marked function
4、mark: Mark , Need to be in pytest.ini The document states the mark
pytest.ini Marked in ,-m Indicates that only the marked test cases are run
main Write in :pytest.main(["-m smoke","-v"]( Multiple labels can be placed )
Marking range : The test case , Test class , modular
class TestCase(object):
# All use cases under this class will have this tag
pytestmark = pytest.mark.xxx
# Multi label mode
pytestmark = [pytest.mark. label 1,pytest.mark. label 2]
# All use cases under this module will have this tag
import pytest
pytestmark = pytest.mark.xxx
# Multi label mode
pytestmark = [pytest.mark. label 1,pytest.mark. label 2]
5、 Failure rerun mechanism
Installing a plug-in :pip install pytest-rerunfailures
Usage mode :pytest --returns 2 Express : A case that fails to run can be run twice
Time delay :pytest --reruns 2 --reruns-delay x( second )
6、main Parameters in
pytest.main(["-s","-v", # Show detailed use case information
"-m"," Mark 1”, # The run is marked 1 The use case
”-m Mark 1 and Mark 2“ # Operation marked 1 And marked 2 The use case
“--html= report.html", # Output html Test report
"--alluredir = allure_dir", # Output allure Test report
"--renruns","2","--reruns-delay","5"]) # Marked with a mark 1 Failure case interval of 5 Second run 2 Time
边栏推荐
- Microservice test efficiency governance
- Getting started with go web programming: validators
- leetcode 279. Perfect squares (medium)
- 数学知识:约数之和—约数
- [roarctf2019] gold 6 years
- [golang] cannot convert expression of type 'interface{}' to type 'string' (solution)
- What do technical people pursue?
- note
- AcWing 第 56 場周賽
- [next] passhref is missing appears after nextjs is packaged
猜你喜欢
随机推荐
过孔式导电滑环怎么用
存储api备忘录
【yarn】Name contains illegal characters
Pseudo instruction in arm assembly
buuctf pwn ciscn_ 2019_ n_ eight
Microservice test efficiency governance
Detailed explanation of IDA static reverse analysis tool
[wechat applet] obtain the current geographic latitude and IP address
一文读懂LiveData 粘性事件
Mathematical knowledge: greatest common divisor divisor
版本动态 | Exchangis 1.0.0-RC1 版本发布
Visualization of camera pose
唐太宗把微服务的“心跳机制”玩到了极致!
数学知识:约数之和—约数
纯净IP怎么判断?哪里有?贵吗?
Thinking about a web offline interview
【Try to Hack】nmap
[typescript] the difference between exclamation mark and question mark in typescript
If a programmer goes to prison, will he be assigned to write code?
汇编语言范例







![[next] passhref is missing appears after nextjs is packaged](/img/86/e1dd1a3ffcdcf749cda565756e99db.png)
