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 測試入門