From b4a9c95f1b055821cb50c76918c497106de7aa54 Mon Sep 17 00:00:00 2001 From: Stas Bekman Date: Mon, 7 Sep 2020 02:50:18 -0700 Subject: [PATCH] [testing] add dependency: parametrize (#6958) unittest doesn't support pytest's super-handy `@pytest.mark.parametrize`, I researched and there are many proposed workarounds, most tedious at best. If we include https://pypi.org/project/parameterized/ in dev dependencies - it will provide a very easy to write parameterization in tests. Same as pytest's fixture, plus quite a few other ways. Example: ``` from parameterized import parameterized @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) ``` (extra `self`var if inside a test class) To remind the pytest style is slightly different: ``` @pytest.mark.parametrize("test_input,expected", [("3+5", 8), ("2+4", 6), ("6*9", 42)]) def test_eval(test_input, expected): ``` More examples here: https://pypi.org/project/parameterized May I suggest that it will make it much easier to write some types of tests? --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0825c8bd04..18475db8f6 100644 --- a/setup.py +++ b/setup.py @@ -89,7 +89,7 @@ extras["onnxruntime"] = ["onnxruntime>=1.4.0", "onnxruntime-tools>=1.4.2"] extras["serving"] = ["pydantic", "uvicorn", "fastapi", "starlette"] extras["all"] = extras["serving"] + ["tensorflow", "torch"] -extras["testing"] = ["pytest", "pytest-xdist", "timeout-decorator", "psutil"] +extras["testing"] = ["pytest", "pytest-xdist", "timeout-decorator", "psutil", "parameterized"] # sphinx-rtd-theme==0.5.0 introduced big changes in the style. extras["docs"] = ["recommonmark", "sphinx", "sphinx-markdown-tables", "sphinx-rtd-theme==0.4.3", "sphinx-copybutton"] extras["quality"] = ["black >= 20.8b1", "isort >= 5", "flake8"]