1. 程式人生 > 其它 >selenium之pytest Fixture:使用Fixture實現案例之間的相互呼叫

selenium之pytest Fixture:使用Fixture實現案例之間的相互呼叫

技術標籤:# pytest重構專案selenium

在這裡插入圖片描述

執行其他函式時都會呼叫執行這個函式
舉例執行:

#使用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