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

边栏推荐
猜你喜欢
随机推荐
2022七夕程序员必备的表白黑科技(七夕限定款)
【字符串函数内功修炼】strlen + strstr + strtok + strerror(三)
Autowired autowiring
三个多月、40余场面试浓缩为6000字
中国的顶级黑客在国际上是一个什么样的水平?
深度学习 RNN架构解析
年薪40W测试工程师成长之路,你在哪个阶段?
SRv6网络的安全解决方案
智慧养老整体解决方案
使用cpolar优化树莓派上的网页(1)
软测人面试 ,HR 会问到哪些问题?学会涨薪3000+
BUG | The interface returns abnormal data
ANT1.7 download and configuration method
2022精选最新金融银行面试真题——附带答案
视频gif如何制作?试试这个视频制作gif神器
Controller层代码这么写,简洁又优雅!
最温馨的家园
【3D建模制作技巧分享】ZBrush模型如何添加不同材质
Service Mesh落地路径
MySQL的JSON 数据类型2









