sklass의 s-class 프로그래밍 blog

[Django] unittest @tag 본문

django

[Django] unittest @tag

sklass 2021. 9. 11. 00:15

django test를 할때 명령어에서 특정 테스트만 테스트하게끔 하고 싶을때 @tag를 사용하면 수월합니다.

아래와 같이 테스트 함수 위에 @tag를 달아주세요.

@tag("greeting")
def test_hello(self) -> None:
	print("hello")

@tag("introduce")
def test_name(self) -> None:
	print("Joseph")
    
@tag("greeting", "welcome")
def test_welcome(self) -> None:
	print("welcome")

이렇게 하고 아래 명령어를 실행하면 됩니다.

python3 manage.py test --tag="greeting"
>> hello
>> welcome
python3 manage.py test --tag="welcome"
>> welcome
python3 manage.py test --tag="greeting" --tag="introduce"
>> hello
>> Joseph
>> welcome
python3 manage.py test --exclude-tag="greeting" --tag="introduce"
>> Joseph

*** 참고로 django unittest는 test함수명의 alphabetical order로 진행됩니다.