当前位置:网站首页>Pytest learning - fixtures
Pytest learning - fixtures
2022-08-04 22:49:00 【51CTO】
1. Fixture details
1.fixture concept fixture is used by pytest to prepare before and after the test (do some pre-steps before running the test case), clean up (deal with the garbage data generated by the test)Code processing mechanism
2, fixture has the following advantages over setup and teardown:
·fixture naming is more flexible and less restrictive
·Data sharing can be realized in the conftest.py configuration, and some configurations can be automatically found without importing
Second, the fixture (@pytest.fixture)
##fixture scope priority (session>module>class>function)
1, (scop = "function") every function or method will be called
Which method you want to use prepend, call it directly
scop= "" (default is function)

2, (scop = "class ") each class is called once
Note that if there is no autouse=true (meaning that all current methods use the pre-method), the pre-method will not be executed

3, (scop = "module") called once per .py file
No matter how many methods or classes are called, they are only executed once in the current .py file

4, (scop = "session") is called once by multiple files, and the .py file is the module
Need to be used in conjunction with conftest.py, only execute once, execute at the beginning

边栏推荐
猜你喜欢
随机推荐
线上虚拟展馆展示具有哪些优势
质量管理大师爱德华·戴明博士经典的质量管理14条原则
good luck
Qt面试题整理
JVM内存配置参数GC日志
力扣24-两两交换链表中的节点——链表
【3D建模制作技巧分享】ZBrush模型如何添加不同材质
今天是七夕,来看看程序员的土味情话。
【C - 基本概念】
js中小数四则运算精度问题原因及解决办法
Redisson
【字符串函数内功修炼】strlen + strstr + strtok + strerror(三)
PHP(3)
剑指 Offer | 03. 数组中重复的数字
线性DP(下)
【模拟面试-10年工作】项目多一定是优势吗?
生成回文数
Charles & TCPDump & Fiddler 抓包三兄弟七夕联手,还抓不到你的心?
QT[一] 信号与槽
Reconfigure the ffmpeg plugin in chrome









