当前位置:网站首页>Pytest custom hook function
Pytest custom hook function
2022-07-28 19:10:00 【Xiaowu knock code】
Except the system mentioned HOOK Out of function , You can also customize HOOK To achieve the desired function .
First create a py file , It defines its own HOOK function , The main pytest Inside hook Function must be in pytest start .
#myhook.py
def pytest_myhook(user):
""" Customize HOOK function """
def pytest_myhook2():
""" Customize HOOK function """
Secondly, create your own plug-in class ,user Class __init__ Method , Bring in when registering the hook pytest Of config To configure . Set the hook entry in this method :self
.config.hook.pytest_myhook().
# Plug in class
class user:
name = "herry"
age = 18
def __init__(self, config):
self.config = config
self.config.hook.pytest_myhook(user=self)
self.config.hook.pytest_myhook2()
@pytest.mark.A
def test_B():
print("BBB")
if __name__ == "__main__":
pytest.main([("pytest Module sharing hook2.py"), ("-s"), ("-m=A")])
Last in conftest.py Register the hook and reference in the file to implement it . Among them, the registration method should be put in the front .
Add the structure first , Registering plug-ins ,
def pytest_addhooks(pluginmanager):
from . import myhook
pluginmanager.add_hookspecs(myhook)
def pytest_configure(config):
config.user_ = user(config)
config.pluginmanager.register(config.user_)
def pytest_myhook(user):
print("username------%s"%user.name)
print("age------%s" % user.age)
def pytest_myhook2():
print("myhook2")
Execution results :

Finally, thank everyone who reads my article carefully , The following online link is also a very comprehensive one that I spent a few days sorting out , I hope it can also help you in need !

These materials , For those who want to change careers 【 software test 】 For our friends, it should be the most comprehensive and complete war preparation warehouse , This warehouse also accompanied me through the most difficult journey , I hope it can help you ! Everything should be done as soon as possible , Especially in the technology industry , We must improve our technical skills . I hope that's helpful ……
If you don't want to grow up alone , Unable to find the information of the system , The problem is not helped , If you insist on giving up after a few days , You can click the small card below to join our group , We can discuss and exchange , There will be various software testing materials and technical exchanges .
Typing is not easy , If this article is helpful to you , Click a like, collect a hide and pay attention , Give the author an encouragement . It's also convenient for you to find it quickly next time .
Self study recommendation B Stop video :
Zero basis transition software testing : Self taught software testing , Got the byte test post offer, Is the B The best video station !
Advanced automation testing : Huawei has landed , Salary increase 20K,2022 Most suitable for self-study python Automated test tutorial , Spend it yourself 16800 Bought , Free sharing

边栏推荐
- Interviewer: what are the usage scenarios of ThreadLocal? How to avoid memory leakage?
- New progress in the implementation of the industry | the openatom openharmony sub forum of the 2022 open atom global open source summit was successfully held
- 6-20漏洞利用-proftpd测试
- 【物理应用】大气吸收损耗附matlab代码
- uwb模块实现人员精确定位,超宽带脉冲技术方案,实时厘米级定位应用
- 11 年膨胀 575 倍,微信为何从“小而美”变成了“大而肥”?
- The difference between --save Dev and --save in NPM
- Creating new projects and adding your own programs
- kotlin:out in
- How to write a JMeter script common to the test team
猜你喜欢

Redis cache avalanche, penetration, breakdown, bloom filter, detailed explanation of distributed lock

配置教程:新版本EasyCVR(v2.5.0)组织结构如何级联到上级平台?

N32替换STM32,这些细节别忽略!

kotlin:Nothing

Introduction and advanced MySQL (7)

真正的 HTAP 对用户和开发者意味着什么?

【数据分析】基于MATLAB实现SVDD决策边界可视化

优麒麟系统安装BeyondComare

N32 replaces STM32. Don't ignore these details!

SQL custom automatic calculation
随机推荐
Kotlin:Sealed class密封类详解
How to obtain data on mobile phones and web pages after the SCM data is uploaded to Alibaba cloud Internet of things platform?
关于ASM冗余问题
QT widget promoted to QWidget
Haproxy implements proxy configuration
【物理应用】大气吸收损耗附matlab代码
The ever-changing pointer ----- C language
Is software testing really as good as online?
Win11电脑摄像头打开看不见,显示黑屏如何解决?
ECS 5 workflow
“讳疾忌医”的开源走不远
New upgrade! The 2022 white paper on cloud native architecture was released
Is there any prospect and way out for software testing?
When the new version of easycvr is linked at the same level, the subordinate platform passes up the cause analysis of the incomplete display of the hierarchical directory
Kotlin:sealed Class detailed explanation of sealed class
What kind of knowledge payment system functions are more conducive to the development of the platform and lecturers?
Structure and working principle of thyristor
How much is software testing training generally?
How long does software testing take?
Interviewer: what are the usage scenarios of ThreadLocal? How to avoid memory leakage?