加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

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

发布时间:2020-12-14 00:24:05 所属栏目:Linux 来源:网络整理
导读: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前置执行log
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读