pytest--fixture---自动应用

import pytest
@pytest.fixture(autouse=True)-----加上auto=True,每个方法执行前都会自动登陆
def login_r(open_browser):
print('登陆')

@pytest.fixture()
def open_browser():
print('打开浏览器')

def test_soso():
print('case3')

# @pytest.mark.usefixtures('lgoin_r')
def test_cart():
print('case4')

if __name__ == '__main__':
pytest.main()

打开浏览器
登陆
PASSED [ 50%]case3

pytest_twofixture.py::test_cart 打开浏览器
登陆
PASSED [100%]case4

猜你喜欢

转载自www.cnblogs.com/QaStudy/p/11565303.html
今日推荐