Skip to content

Unittest-parametrize

Parametrize tests within unittest TestCases.

참고로 pytest의 @pytest.mark.parametrize데코레이터는 unittest.TestCase 클래스를 상속받는 구조에서는 작동하지 않는다.

Installation

Install with:

python -m pip install unittest-parametrize

Python 3.8 to 3.12 supported.

Usage

from unittest_parametrize import parametrize
from unittest_parametrize import ParametrizedTestCase


class SquareTests(ParametrizedTestCase):
    @parametrize(
        "x,expected",
        [
            (1, 1),
            (2, 4),
        ],
    )
    def test_square(self, x: int, expected: int) -> None:
        self.assertEqual(x**2, expected)

See also

Favorite site