Description
Parameterized testing with any Python test framework ==================================================== .. image:: https://img.shields.io/pypi/v/parameterized :alt: PyPI :target: https://pypi.org/project/parameterized/ .. image:: https://img.shields.io/pypi/dm/parameterized :alt: PyPI - Downloads :target: https://pypi.org/project/parameterized/ .. image:: https://circleci.com/gh/wolever/parameterized.svg?style=svg :alt: Circle CI :target: https://circleci.com/gh/wolever/parameterized Parameterized testing in Python sucks. ``parameterized`` fixes that. For everything. Parameterized testing for nose, parameterized testing for py.test, parameterized testing for unittest. .. code:: python # test_math.py from nose.tools import assert_equal from parameterized import parameterized, parameterized_class import unittest import math @parameterized([ (2, 2, 4), (2, 3, 8), (1, 9, 1), (0, 9, 0), ]) def test_pow(base, exponent, expected): assert_equal(math.pow(base, exponent), expected) class TestMathUnitTest(unittest.TestCase): @parameterized.expand([ ("negative", -1.5, -2.0), ("integer", 1, 1.0), ("large fraction", 1.6, 1), ]) def test_floor(self, name, input, expected): assert_equal(math.floor(input), expected) @parameterized_class(('a', 'b', 'expected_sum', 'expected_product'), [ (1, 2, 3, 2), (5, 5, 10, 25), ]) class TestMathClass(unittest.TestCase): def test_add(self): assert_equal(self.a + self.b, self.expected_sum) def test_multiply(self): assert_equal(self.a * self.b, self.expected_product) @parameterized_class([ { "a": 3, "expected": 2 }, { "b": 5, "expected": -4 }, ]) class TestMathClassDict(unittest.TestCase): a = 1 b = 1 def test_subtract(self): assert_equal(self.a - self.b, self.expected) With nose (and nose2):: $ nosetests -v test_math.py test_floor_0_negative (test_math.TestMathUnitTest) ... ok test_floor_1_integer (test_math.TestMathUnitTest) ... ok test_floor_2_large_fraction (test_math.TestMathUnitTest) ... ok test_math.test_pow(2, 2, 4, {}) ... ok test_math.test_pow(2, 3, 8, {}) ... ok test_math.test_pow(1, 9, 1, {}) ... ok test_math.test_pow(0, 9, 0, {}) ... ok test_add (test_math.TestMathClass_0) ... ok test_multiply (test_math.TestMathClass_0) ... ok test_add (test_math.TestMathClass_1) ... ok test_multiply (test_math.TestMathClass_1) ... ok test_subtract (test_math.TestMathClassDict_0) ... ok ---------------------------------------------------------------------- Ran 12 tests in 0.015s OK As the package name suggests, nose is best supported and will be used for all further examples. With py.test (version 2.0 and above):: $ py.test -v test_math.py ============================= test session starts ============================== platform darwin -- Python 3.6.1, pytest-3.1.3, py-1.4.34, pluggy-0.4.0 collecting ... collected 13 items test_math.py::test_pow::[0] PASSED test_math.py::test_pow::[1] PASSED test_math.py::test_pow::[2] PASSED test_math.py::test_pow::[3] PASSED test_math.py::TestMathUnitTest::test_floor_0_negative PASSED test_math.py::TestMathUnitTest::test_floor_1_integer PASSED test_math.py::TestMathUnitTest::test_floor_2_large_fraction PASSED test_math.py::TestMathClass_0::test_add PASSED test_math.py::TestMathClass_0::test_multiply PASSED test_math.py::TestMathClass_1::test_add PASSED test_math.py::TestMathClass_1::test_multiply PASSED test_math.py::TestMathClassDict_0::test_subtract PASSED ==================== 12 passed, 4 warnings in 0.16 seconds ===================== With unittest (and unittest2):: $ python -m unittest -v test_math test_floor_0_negative (test_math.TestMathUnitTest) ... ok test_floor_1_integer (test_math.TestMathUnitTest) ... ok test_floor_2_large_fraction (test_math.TestMathUnitTest) ... ok test_add (test_math.TestMathClass_0) ... ok test_multiply (test_math.TestMathClass_0) ... ok test_add (test_math.TestMathClass_1) ... ok test_multiply (test_math.TestMathClass_1) ... ok test_subtract (test_math.TestMathClassDict_0) ... ok ---------------------------------------------------------------------- Ran 8 tests in 0.001s OK (note: because unittest does not support test decorators, only tests created with ``@parameterized.expand`` will be executed) With green:: $ green test_math.py -vvv test_math TestMathClass_1 . test_method_a . test_method_b TestMathClass_2 . test_method_a . test_method_b TestMathClass_3 . test_method_a . test_method_b TestMathUnitTest . test_floor_0_negative . test_floor_1_integer . test_floor_2_large_fraction TestMathC
Release History
| Version | Changes | Urgency | Date |
|---|---|---|---|
| 0.9.0 | Imported from PyPI (0.9.0) | Low | 4/21/2026 |
| v0.9.0 | Tag v0.9.0 | Low | 3/27/2023 |
| v0.8.1 | Tag v0.8.1 | Low | 1/9/2021 |
| v0.8.0 | Tag v0.8.0 | Low | 1/4/2021 |
| v0.7.5 | Tag v0.7.5 | Low | 1/4/2021 |
| v0.7.4 | Tag v0.7.4 | Low | 4/14/2020 |
| v0.7.3 | Tag v0.7.3 | Low | 4/12/2020 |
| v0.7.1 | Tag v0.7.1 | Low | 11/19/2019 |
| v0.3.5 | Tag v0.3.5 | Low | 11/6/2014 |
| v0.3.4 | Tag v0.3.4 | Low | 10/3/2014 |
