当前位置:网站首页>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

边栏推荐
- SwiftUI 组件之如何实现电话号码掩码隐藏部分的文本字段TextField(教程含源码)
- Implementation of grayscale publishing with haproxy
- Is there a future for changing careers in learning software testing?
- QT running image
- 关于ASM冗余问题
- Lookup - lookup of sequential table and ordered table
- Self cultivation of Electronic Engineers - when a project is developed
- How much is software testing training generally?
- Is software testing really as good as online?
- What is one hot code? Why use it and when?
猜你喜欢

1、 My first wechat applet

Easynlp Chinese text and image generation model takes you to become an artist in seconds

Win11系统svchost.exe一直在下载怎么办?

6-20漏洞利用-proftpd测试

JVM four reference types

Interpretation of ue4.25 slate source code

【物理应用】水下浮动风力涡轮机的尾流诱导动态模拟风场附matlab代码

Introduction and advanced MySQL (7)

What is one hot code? Why use it and when?

How to write a JMeter script common to the test team
随机推荐
行业落地呈现新进展 | 2022开放原子全球开源峰会OpenAtom OpenHarmony分论坛圆满召开
How much is software testing training generally?
If you want to learn software testing, where can you learn zero foundation?
Open source database innovation in the era of digital economy | the 2022 open atom global open source summit database sub forum was successfully held
The ever-changing pointer ----- C language
[machine learning] support vector machine classification
Introduction and advanced MySQL (III)
湖上建仓全解析:如何打造湖仓一体数据平台 | DEEPNOVA技术荟系列公开课第四期
Is two months of software testing training reliable?
QT widget promoted to QWidget
2022 Hangdian multi school field 2 1011 DOS card (line segment tree)
Introduction and advanced level of MySQL (II)
Use the self-developed proxy server to solve the cross domain access errors encountered when uploading files by SAP ui5 fileuploader trial version
How does the mqtt server built with emqx forward data and save it to the cloud database?
kotlin:Nothing
Remember a uniapp experience
unity CS1513
The wechat installation package has expanded 575 times in 11 years, and the up owner: "98% of the documents are garbage"; Apple App store was exposed to a large number of pornographic apps; Four techn
SwiftUI Swift 之正向地理编码与反向地理编码(教程含源码)
视频融合云服务EasyCVR平台白名单功能如何使用?