본문 바로가기
🎪 놀고있네/Python

[Python] PyTest - Handling Failures

by 냥장판 2024. 5. 8.
반응형

아래와 같은 예제 코드가 있음

import pytest

def test_greater():
   num = 10
   assert num > 100

def test_greater_equal():
   num = 10
   assert num >= 10
   
def test_less():
   num = 200
   assert num < 200
   
def test_not_greater_than():
    num = 200
    assert num < 201 

def test_fail1():
   num = 0.3
   assert num == 6
   
def test_fail2():
   num = 83749
   assert num == 6

 

실행해보면 

4 failed, 2 passed 로 결과가 출력됨

 

명령어를 통해서 fail 케이스에 따라 실행을 중지시킬 수 있다.

pytest -x TEST/test_failure.py -v # stop after first failure

 

 

 

2 개면 중지

pytest --maxfail=2 TEST/test_failure.py -v # stop after two failures

 

반응형

댓글