usefixtures是fixture另外的一种调用方式,是下面格式中的第二种:
前提:定义了一个fixture方法。现在要调用。
第一种,可以接收返回值:
def test_func(func):
xxx
第二种,无法接收返回值:
@pytest.mark.usefixtures('func')
def test_func():
xxx
第一种是我们之前文章中已经使用的方法。第二种usefixture无法接收返回值,在方法不需要返回值时使用就会更直观地看出调用了fixture方法。
注意:@pytest.mark.usefixtures('use_fixture', 'use_fixture2')括号中是字符串格式。