None

生命就像一条蜿蜒的河流

导航

pytest fixture:使用fixture实现用例之间的调用

pytest fixture

定义fixture跟定义普通的函数差不多,唯一的区别就是在函数上加个装饰器@pytest.fixture()

fixture命名不要以test开头,跟用例区别开。fixture是有函数返回值的,没有返回值默认None

用例调用fixture的返回值,直接就是吧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(['-vs','test06.py'])

 

posted on 2021-03-01 15:26  我睡着了  阅读(156)  评论(0编辑  收藏  举报