Python 테스트 입문
Alexander Levin
Data Scientist
피크닉 준비를 떠올려 봅시다:
픽스처는 다음에 도움이 됩니다:
다음이 있다고 가정합시다:
data라는 Python list 변수data = [0, 1, 1, 2, 3, 5, 8, 13, 21]그리고 다음을 확인하고 싶습니다:
5와 21을 포함하는지import pytest
# Fixture decorator
@pytest.fixture
# Fixture for data initialization
def data():
return [0, 1, 1, 2, 3, 5, 8, 13, 21]
def test_list(data):
assert len(data) == 9
assert 5 in data
assert 21 in data
예제 출력:

픽스처를 사용하려면 다음을 수행합니다:
@pytest.fixture 데코레이터 선언테스트 픽스처를 학습했습니다:
list 준비@pytest.fixture로 pytest 픽스처 정의Python 테스트 입문