selenium之pytest Fixture:使用Fixture实现案例之间的相互调用

在这里插入图片描述

运行其他函数时都会调用运行这个函数
举例运行:

#使用Fixture实现案例之间的相互调用

import pytest

@pytest.fixture()
def init():
    print('init....')
    return 1

def test1(init):
    print("test1")

def test2(init):
    print('test2')
    
    
if __name__ == '__main__':
    pytest.main('-sv','test06.py')

运行结果:

============================ test session starts =============================
platform win32 -- Python 3.6.3, pytest-6.2.1, py-1.10.0, pluggy-0.13.1 -- C:\ProgramData\Anaconda3\python.exe
cachedir: .pytest_cache
metadata: {'Python': '3.6.3', 'Platform': 'Windows-10-10.0.17763-SP0', 'Packages': {'pytest': '6.2.1', 'py': '1.10.0', 'pluggy': '0.13.1'}, 'Plugins': {'html': '3.1.1', 'metadata': '1.11.0'}, 'JAVA_HOME': 'E:\\Program Files\\jdk1.8.0_171'}
rootdir: C:\Users\Administrator\pythonxiangmu\seelenium_project\testcases\pytest, configfile: pytest.ini
plugins: html-3.1.1, metadata-1.11.0
collecting ... collected 2 items

test06.py::test1 init....
PASSED                                                  [ 50%]test1

test06.py::test2 init....
PASSED                                                  [100%]test2


============================== 2 passed in 0.07s ==============================

Process finished with exit code 0

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值