pytest (三) fixture autouse参数使用

# autouse 默认是False

import pytest

@pytest.fixture(autouse=False)
def begin():
  print('执行 begin')

# autouse是False,则需要在测试用例中加入参数begin
def test_a(begin):
  print('执行 test_a')

# 结果如下
'''
执行 begin
执行 test_a
'''
import pytest

@pytest.fixture(autouse=True)
def begin():
  print('执行 begin')

# autouse是Ture,则不需要在测试用例中加入参数begin
def test_a():
  print('执行 test_a')

# 结果如下
'''
执行 begin
执行 test_a
'''
posted @ 2025-03-17 22:21  アーニャ  阅读(87)  评论(0)    收藏  举报