首页 > 其他 > 详细

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

时间:2019-09-21 23:21:00      阅读:211      评论:0      收藏:0      [点我收藏+]
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

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

原文:https://www.cnblogs.com/QaStudy/p/11565337.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!