Python 테스트 입문
Alexander Levin
Data Scientist
autouse=True이면 요청과 무관하게 픽스처 함수가 실행됩니다모든 테스트에 동일한 환경 준비나 수정을 적용해야 할 때 사용합니다.
예를 들어 모든 테스트가 다음을 보장해야 할 때:
이런 경우는 모두 "autouse" 인자로 처리합니다.
"autouse"된 픽스처 예시:
import pytest
import pandas as pd
# Autoused fixture
@pytest.fixture(autouse=True)
def set_pd_options():
pd.set_option('display.max_columns', 5000)
# Test function
def test_pd_options():
assert pd.get_option('display.max_columns') == 5000
잘못된 "autouse" 픽스처 예시:
import pytest
import pandas as pd
# Wrong autoused fixture
@pytest.fixture(autouse=True)
def wrong_fixture():
return [1,2,3,4,5]
# Test function
def test_type():
assert type(wrong_fixture) == list
수정된 픽스처 예시:
import pytest
import pandas as pd
# Wrong autoused fixture
@pytest.fixture
def correct_fixture():
return [1,2,3,4,5]
# Test function
def test_type(correct_fixture):
assert type(correct_fixture) == list
예시 출력:

autouse 정의: 픽스처 데코레이터의 선택적 불리언 인자@pytest.fixture(autouse=True)autouse=True이면 요청과 무관하게 픽스처 함수가 실행됩니다Python 테스트 입문