Python 测试入门
Alexander Levin
Data Scientist

链式调用 fixtures 有助于:
适用场景:
# 被其他 fixture 请求的 fixture
@pytest.fixture
def setup_data():
return "I am a fixture!"
# 被测试函数请求的 fixture
@pytest.fixture
def process_data(setup_data):
return setup_data.upper()
# 测试函数
def test_process_data(process_data):
assert process_data == "I AM A FIXTURE!"
pytest fixtures# 请求其他 fixture 的 fixture
@pytest.fixture
def process_data(setup_data):
return setup_data.upper()
Python 测试入门