pytest--fixure前置执行一个函数

import pytest
@pytest.fixture()
def login_r():
print('登陆')

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

def test_soso():
print('case3')

@pytest.mark.usefixtures('login_r')----通过usefixtures可以让test_cart前置执行login
def test_cart():
print('case4')

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

pytest_twofixture.py::test_soso PASSED [ 50%]case3

pytest_twofixture.py::test_cart 登陆
PASSED [100%]case4

 

案例2

import pytest
@pytest.fixture()
def login_r(open_browser):
print('登陆')

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

def test_soso():
print('case3')

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

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

pytest_twofixture.py::test_soso PASSED [ 50%]case3

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

posted on 2019-09-21 23:06  barton123  阅读(406)  评论(0编辑  收藏  举报

导航