yeomko22 / TIL

Today I learned
1 stars 0 forks source link

DS school - Unit testing production model #124

Open yeomko22 opened 2 years ago

yeomko22 commented 2 years ago

python convention

type hints

import typing as t

def add_two_integers(first: int, second: t.Optional[int] = None) -> int:
    """Sum two numbers."""
    result = first
    if second:
        result = first + second
    return result
yeomko22 commented 2 years ago

pytest

@pytest.fixture def input_value(): return 4

- 그 외에 @pytest.mark.parametrize 데코레이터를 사용하면 배열을 인풋으로 쉽게 선언할 수 있다.

~~~python
# test_my_module.py
from my_module import square

def test_squre_gives_correct_value(input_value):
    subject = square(input_value)
    assert subject == 16