当前位置:网站首页>(6) Decorator extension [email protected] Principle of use
(6) Decorator extension [email protected] Principle of use
2022-07-24 02:43:00 【It's hard to recover】
( One )@pytest.mark.XXX How did it happen ?
Children's shoes that have played interface automation have been used pytest, Basically, it is realized by decorators , In the last few articles, we talked about the operating principle of the decorator , This time we expand a new knowledge point :@pytest.mark.XXX What is the implementation principle ?
import pytest
@pytest.mark.skip
def test():
passLet's take an example :
@pytest.mark.skip It's actually using pytest In the module mark This object .skip Method
@ modular . object . Method
( Two ) Let's implement a decorator of this form by ourselves
(1) We build a new one lemon.py file , Create a Mark class , Write the inside skip function ,skip There is a nested function in the function wrapper.

(2) Build another one demo1_ Decorator extension .py file , Create a test2 Method , then @lemon.mark.skip, Finally, call below test2() try .

Print the results :
----skip----1
------test2------
----skip----2
Let's try the source code for you
from py09_07day import lemon
class Mark:
def skip(self, func):
def wrapper(*args, **kwargs):
print("----skip----1")
res = func()
print("----skip----2")
return res
return wrapper
mark = Mark()
# @lemon.mark.skip ===> @lemon This class .mark object . Method
# @skip test2 = skip(test2)
@lemon.mark.skip
def test2():
print('------test2------')
test2()
# Print the results
----skip----1
------test2------
----skip----2边栏推荐
- Camper recruitment | AI youth with the world in mind, the United Nations needs your help for sustainable development!
- 微信小程序实现折线面积图-玫瑰图-立体柱状图
- Correlation
- Audio processing based on time-frequency diagram matlab
- 【补题日记】[2022牛客暑期多校2]K-Link with Bracket Sequence I
- wallys/WiFi6 MiniPCIe Module 2T2R2 × 2.4GHz 2x5GHz MT7915 MT7975
- [untitled]
- Analyze the overall planning of steam and maker education classroom
- Doodle icons - a free commercial graffiti style icon library, cute, light and unique
- 【补题日记】[2022牛客暑期多校1]C-Grab the Seat
猜你喜欢

redis数据类型概念
![JS when transferring parameters, the incoming string has data; No data when number is passed in; 2[0] is right! Number type data can be subscripted](/img/4e/3d0c25d9579b6d5c00473048dbbd83.png)
JS when transferring parameters, the incoming string has data; No data when number is passed in; 2[0] is right! Number type data can be subscripted

SSM的技术论坛含前后台

Composition API (in setup) watch usage details

UIE: 信息抽取的大一统模型

Use the pagoda panel to plan tasks and automatically push the website to Baidu for inclusion

Make life full of happiness

Camper recruitment | AI youth with the world in mind, the United Nations needs your help for sustainable development!

Jina AI 联合Datawhale,发起学习项目!

攻防世界WEB练习区(weak_auth、simple_php、xff_referer)
随机推荐
Composition API (in setup) watch usage details
Cloud native explanation [expansion]
[diary of supplementary questions] [2022 Hangdian summer school 1] c-backpack
22 -- 二叉搜索树的范围和
Do securities companies really have principal guaranteed financial products?
老公,我们现在无家可归了
Summary of problems encountered in the development process in July
Mysql database, grouping function
Recommendation system topic | recommendation system architecture and single domain cross domain recall model
Jina AI 联合Datawhale,发起学习项目!
SIGIR‘22 推荐系统论文之多样性篇
Rylstim Screen Recorder
Réalisation d'un diagramme de zone de ligne brisée - Diagramme Rose - Diagramme à barres
“我们为什么要做 iVX ? ” ——访 iVX CEO 孟智平 了解 iVX 企业文化
Is it safe to open an account for Xiaobai stock? Can I apply online?
Jina AI and datawhale jointly launched a learning project!
js傳參時傳入 string有數據;傳入 number時沒有數據;2[0]是對的!number類型數據可以取下標
分享一个基于Abp 和Yarp 开发的API网关项目
Responsive pbootcms template decoration design website
IBM: realize the quantum advantage of fault tolerance by 2030