{ "info": { "author": "David Wolever", "author_email": "david@wolever.net", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: BSD License", "Programming Language :: Python", "Programming Language :: Python :: 3" ], "description": "Parameterized testing with any Python test framework\n====================================================\n\n.. image:: https://travis-ci.org/wolever/parameterized.svg?branch=master\n :target: https://travis-ci.org/wolever/parameterized\n\nParameterized testing in Python sucks.\n\n``parameterized`` fixes that. For everything. Parameterized testing for nose,\nparameterized testing for py.test, parameterized testing for unittest.\n\n.. code:: python\n\n # test_math.py\n from nose.tools import assert_equal\n from parameterized import parameterized, parameterized_class\n\n import unittest\n import math\n\n @parameterized([\n (2, 2, 4),\n (2, 3, 8),\n (1, 9, 1),\n (0, 9, 0),\n ])\n def test_pow(base, exponent, expected):\n assert_equal(math.pow(base, exponent), expected)\n\n class TestMathUnitTest(unittest.TestCase):\n @parameterized.expand([\n (\"negative\", -1.5, -2.0),\n (\"integer\", 1, 1.0),\n (\"large fraction\", 1.6, 1),\n ])\n def test_floor(self, name, input, expected):\n assert_equal(math.floor(input), expected)\n\n @parameterized_class(('a', 'b', 'expected_sum', 'expected_product'), [\n (1, 2, 3, 2),\n (5, 5, 10, 25),\n ])\n class TestMathClass(unittest.TestCase):\n def test_add(self):\n assert_equal(self.a + self.b, self.expected_sum)\n\n def test_multiply(self):\n assert_equal(self.a * self.b, self.expected_product)\n\n @parameterized_class([\n { \"a\": 3, \"expected\": 2 },\n { \"b\": 5, \"expected\": -4 },\n ])\n class TestMathClassDict(unittest.TestCase):\n a = 1\n b = 1\n\n def test_subtract(self):\n assert_equal(self.a - self.b, self.expected)\n\n\nWith nose (and nose2)::\n\n $ nosetests -v test_math.py\n test_floor_0_negative (test_math.TestMathUnitTest) ... ok\n test_floor_1_integer (test_math.TestMathUnitTest) ... ok\n test_floor_2_large_fraction (test_math.TestMathUnitTest) ... ok\n test_math.test_pow(2, 2, 4, {}) ... ok\n test_math.test_pow(2, 3, 8, {}) ... ok\n test_math.test_pow(1, 9, 1, {}) ... ok\n test_math.test_pow(0, 9, 0, {}) ... ok\n test_add (test_math.TestMathClass_0) ... ok\n test_multiply (test_math.TestMathClass_0) ... ok\n test_add (test_math.TestMathClass_1) ... ok\n test_multiply (test_math.TestMathClass_1) ... ok\n test_subtract (test_math.TestMathClassDict_0) ... ok\n\n ----------------------------------------------------------------------\n Ran 12 tests in 0.015s\n\n OK\n\nAs the package name suggests, nose is best supported and will be used for all\nfurther examples.\n\n\nWith py.test (version 2.0 and above)::\n\n $ py.test -v test_math.py\n ============================= test session starts ==============================\n platform darwin -- Python 3.6.1, pytest-3.1.3, py-1.4.34, pluggy-0.4.0\n collecting ... collected 13 items\n\n test_math.py::test_pow::[0] PASSED\n test_math.py::test_pow::[1] PASSED\n test_math.py::test_pow::[2] PASSED\n test_math.py::test_pow::[3] PASSED\n test_math.py::TestMathUnitTest::test_floor_0_negative PASSED\n test_math.py::TestMathUnitTest::test_floor_1_integer PASSED\n test_math.py::TestMathUnitTest::test_floor_2_large_fraction PASSED\n test_math.py::TestMathClass_0::test_add PASSED\n test_math.py::TestMathClass_0::test_multiply PASSED\n test_math.py::TestMathClass_1::test_add PASSED\n test_math.py::TestMathClass_1::test_multiply PASSED\n test_math.py::TestMathClassDict_0::test_subtract PASSED\n ==================== 12 passed, 4 warnings in 0.16 seconds =====================\n\nWith unittest (and unittest2)::\n\n $ python -m unittest -v test_math\n test_floor_0_negative (test_math.TestMathUnitTest) ... ok\n test_floor_1_integer (test_math.TestMathUnitTest) ... ok\n test_floor_2_large_fraction (test_math.TestMathUnitTest) ... ok\n test_add (test_math.TestMathClass_0) ... ok\n test_multiply (test_math.TestMathClass_0) ... ok\n test_add (test_math.TestMathClass_1) ... ok\n test_multiply (test_math.TestMathClass_1) ... ok\n test_subtract (test_math.TestMathClassDict_0) ... ok\n\n ----------------------------------------------------------------------\n Ran 8 tests in 0.001s\n\n OK\n\n(note: because unittest does not support test decorators, only tests created\nwith ``@parameterized.expand`` will be executed)\n\nWith green::\n\n $ green test_math.py -vvv\n test_math\n TestMathClass_1\n . test_method_a\n . test_method_b\n TestMathClass_2\n . test_method_a\n . test_method_b\n TestMathClass_3\n . test_method_a\n . test_method_b\n TestMathUnitTest\n . test_floor_0_negative\n . test_floor_1_integer\n . test_floor_2_large_fraction\n TestMathClass_0\n . test_add\n . test_multiply\n TestMathClass_1\n . test_add\n . test_multiply\n TestMathClassDict_0\n . test_subtract\n\n Ran 12 tests in 0.121s\n\n OK (passes=9)\n\n\nInstallation\n------------\n\n::\n\n $ pip install parameterized\n\n\nCompatibility\n-------------\n\n`Yes`__.\n\n__ https://travis-ci.org/wolever/parameterized\n\n.. list-table::\n :header-rows: 1\n :stub-columns: 1\n\n * -\n - Py2.6\n - Py2.7\n - Py3.4\n - Py3.5\n - Py3.6\n - Py3.7\n - PyPy\n * - nose\n - yes\n - yes\n - yes\n - yes\n - yes\n - yes\n - yes\n * - nose2\n - yes\n - yes\n - yes\n - yes\n - yes\n - yes\n - yes\n * - py.test\n - yes\n - yes\n - yes\n - yes\n - yes\n - yes\n - yes\n * - | unittest\n | (``@parameterized.expand``)\n - yes\n - yes\n - yes\n - yes\n - yes\n - yes\n - yes\n * - | unittest2\n | (``@parameterized.expand``)\n - yes\n - yes\n - yes\n - yes\n - yes\n - yes\n - yes\n\nDependencies\n------------\n\n(this section left intentionally blank)\n\n\nExhaustive Usage Examples\n--------------------------\n\nThe ``@parameterized`` and ``@parameterized.expand`` decorators accept a list\nor iterable of tuples or ``param(...)``, or a callable which returns a list or\niterable:\n\n.. code:: python\n\n from parameterized import parameterized, param\n\n # A list of tuples\n @parameterized([\n (2, 3, 5),\n (3, 5, 8),\n ])\n def test_add(a, b, expected):\n assert_equal(a + b, expected)\n\n # A list of params\n @parameterized([\n param(\"10\", 10),\n param(\"10\", 16, base=16),\n ])\n def test_int(str_val, expected, base=10):\n assert_equal(int(str_val, base=base), expected)\n\n # An iterable of params\n @parameterized(\n param.explicit(*json.loads(line))\n for line in open(\"testcases.jsons\")\n )\n def test_from_json_file(...):\n ...\n\n # A callable which returns a list of tuples\n def load_test_cases():\n return [\n (\"test1\", ),\n (\"test2\", ),\n ]\n @parameterized(load_test_cases)\n def test_from_function(name):\n ...\n\n.. **\n\nNote that, when using an iterator or a generator, all the items will be loaded\ninto memory before the start of the test run (we do this explicitly to ensure\nthat generators are exhausted exactly once in multi-process or multi-threaded\ntesting environments).\n\nThe ``@parameterized`` decorator can be used test class methods, and standalone\nfunctions:\n\n.. code:: python\n\n from parameterized import parameterized\n\n class AddTest(object):\n @parameterized([\n (2, 3, 5),\n ])\n def test_add(self, a, b, expected):\n assert_equal(a + b, expected)\n\n @parameterized([\n (2, 3, 5),\n ])\n def test_add(a, b, expected):\n assert_equal(a + b, expected)\n\n\nAnd ``@parameterized.expand`` can be used to generate test methods in\nsituations where test generators cannot be used (for example, when the test\nclass is a subclass of ``unittest.TestCase``):\n\n.. code:: python\n\n import unittest\n from parameterized import parameterized\n\n class AddTestCase(unittest.TestCase):\n @parameterized.expand([\n (\"2 and 3\", 2, 3, 5),\n (\"3 and 5\", 2, 3, 5),\n ])\n def test_add(self, _, a, b, expected):\n assert_equal(a + b, expected)\n\nWill create the test cases::\n\n $ nosetests example.py\n test_add_0_2_and_3 (example.AddTestCase) ... ok\n test_add_1_3_and_5 (example.AddTestCase) ... ok\n\n ----------------------------------------------------------------------\n Ran 2 tests in 0.001s\n\n OK\n\nNote that ``@parameterized.expand`` works by creating new methods on the test\nclass. If the first parameter is a string, that string will be added to the end\nof the method name. For example, the test case above will generate the methods\n``test_add_0_2_and_3`` and ``test_add_1_3_and_5``.\n\nThe names of the test cases generated by ``@parameterized.expand`` can be\ncustomized using the ``testcase_func_name`` keyword argument. The value should\nbe a function which accepts three arguments: ``testcase_func``, ``param_num``,\nand ``params``, and it should return the name of the test case.\n``testcase_func`` will be the function to be tested, ``param_num`` will be the\nindex of the test case parameters in the list of parameters, and ``param``\n(an instance of ``param``) will be the parameters which will be used.\n\n.. code:: python\n\n import unittest\n from parameterized import parameterized\n\n def custom_name_func(testcase_func, param_num, param):\n return \"%s_%s\" %(\n testcase_func.__name__,\n parameterized.to_safe_name(\"_\".join(str(x) for x in param.args)),\n )\n\n class AddTestCase(unittest.TestCase):\n @parameterized.expand([\n (2, 3, 5),\n (2, 3, 5),\n ], testcase_func_name=custom_name_func)\n def test_add(self, a, b, expected):\n assert_equal(a + b, expected)\n\nWill create the test cases::\n\n $ nosetests example.py\n test_add_1_2_3 (example.AddTestCase) ... ok\n test_add_2_3_5 (example.AddTestCase) ... ok\n\n ----------------------------------------------------------------------\n Ran 2 tests in 0.001s\n\n OK\n\n\nThe ``param(...)`` helper class stores the parameters for one specific test\ncase. It can be used to pass keyword arguments to test cases:\n\n.. code:: python\n\n from parameterized import parameterized, param\n\n @parameterized([\n param(\"10\", 10),\n param(\"10\", 16, base=16),\n ])\n def test_int(str_val, expected, base=10):\n assert_equal(int(str_val, base=base), expected)\n\n\nIf test cases have a docstring, the parameters for that test case will be\nappended to the first line of the docstring. This behavior can be controlled\nwith the ``doc_func`` argument:\n\n.. code:: python\n\n from parameterized import parameterized\n\n @parameterized([\n (1, 2, 3),\n (4, 5, 9),\n ])\n def test_add(a, b, expected):\n \"\"\" Test addition. \"\"\"\n assert_equal(a + b, expected)\n\n def my_doc_func(func, num, param):\n return \"%s: %s with %s\" %(num, func.__name__, param)\n\n @parameterized([\n (5, 4, 1),\n (9, 6, 3),\n ], doc_func=my_doc_func)\n def test_subtraction(a, b, expected):\n assert_equal(a - b, expected)\n\n::\n\n $ nosetests example.py\n Test addition. [with a=1, b=2, expected=3] ... ok\n Test addition. [with a=4, b=5, expected=9] ... ok\n 0: test_subtraction with param(*(5, 4, 1)) ... ok\n 1: test_subtraction with param(*(9, 6, 3)) ... ok\n\n ----------------------------------------------------------------------\n Ran 4 tests in 0.001s\n\n OK\n\nFinally ``@parameterized.expand_class`` parameterizes an entire class, using\neither a list of attributes, or a list of dicts that will be applied to the\nclass:\n\n.. code:: python\n\n from yourapp.models import User\n from parameterized import parameterized_class\n\n @parameterized_class((\"username\", \"access_level\", \"expected_status_code\"), [\n (\"user_1\", 1, 200),\n (\"user_2\", 2, 404)\n ])\n class TestUserAccessLevel(TestCase):\n def setUp(self):\n self.client.force_login(User.objects.get(username=self.username)[0])\n\n def test_url_a(self):\n response = self.client.get(\"/url\")\n self.assertEqual(response.status_code, self.expected_status_code)\n\n def tearDown(self):\n self.client.logout()\n\n\n @parameterized_class([\n { \"username\": \"user_1\", \"access_level\": 1 },\n { \"username\": \"user_2\", \"access_level\": 2, \"expected_status_code\": 404 },\n ])\n class TestUserAccessLevel(TestCase):\n expected_status_code = 200\n\n def setUp(self):\n self.client.force_login(User.objects.get(username=self.username)[0])\n\n def test_url_a(self):\n response = self.client.get('/url')\n self.assertEqual(response.status_code, self.expected_status_code)\n\n def tearDown(self):\n self.client.logout()\n\n\nMigrating from ``nose-parameterized`` to ``parameterized``\n----------------------------------------------------------\n\nTo migrate a codebase from ``nose-parameterized`` to ``parameterized``:\n\n1. Update your requirements file, replacing ``nose-parameterized`` with\n ``parameterized``.\n\n2. Replace all references to ``nose_parameterized`` with ``parameterized``::\n\n $ perl -pi -e 's/nose_parameterized/parameterized/g' your-codebase/\n\n3. You're done!\n\nUsing with ``mock.patch``\n-------------------------\n\n``parameterized`` can be used with ``mock.patch``, but the argument ordering\ncan be confusing. The ``@mock.patch(...)`` decorator must come *below* the\n``@parameterized(...)``, and the mocked parameters must come *last*::\n\n @mock.patch(\"os.getpid\")\n class TestOS(object):\n @parameterized(...)\n @mock.patch(\"os.fdopen\")\n @mock.patch(\"os.umask\")\n def test_method(self, param1, param2, ..., mock_umask, mock_fdopen, mock_getpid):\n ...\n\nNote: the same holds true when using ``@parameterized.expand``.\n\nFAQ\n---\n\nWhat happened to ``nose-parameterized``?\n Originally only nose was supported. But now everything is supported, and it\n only made sense to change the name!\n\nWhat do you mean when you say \"nose is best supported\"?\n There are small caveates with ``py.test`` and ``unittest``: ``py.test``\n does not show the parameter values (ex, it will show ``test_add[0]``\n instead of ``test_add[1, 2, 3]``), and ``unittest``/``unittest2`` do not\n support test generators so ``@parameterized.expand`` must be used.\n\nWhy not use ``@pytest.mark.parametrize``?\n Because spelling is difficult. Also, ``parameterized`` doesn't require you\n to repeat argument names, and (using ``param``) it supports optional\n keyword arguments.\n\nWhy do I get an ``AttributeError: 'function' object has no attribute 'expand'`` with ``@parameterized.expand``?\n You've likely installed the ``parametrized`` (note the missing *e*)\n package. Use ``parameterized`` (with the *e*) instead and you'll be all\n set.\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/wolever/parameterized", "keywords": "", "license": "FreeBSD", "maintainer": "", "maintainer_email": "", "name": "parameterized", "package_url": "https://pypi.org/project/parameterized/", "platform": "", "project_url": "https://pypi.org/project/parameterized/", "project_urls": { "Homepage": "https://github.com/wolever/parameterized" }, "release_url": "https://pypi.org/project/parameterized/0.7.0/", "requires_dist": null, "requires_python": "", "summary": "Parameterized testing with any Python test framework", "version": "0.7.0" }, "last_serial": 4784845, "releases": { "0.5.0": [ { "comment_text": "", "digests": { "md5": "22576412f8c6e2f9cbea3ddf4ec61dff", "sha256": "b783401b1206f5492f23f4c84f25f802a4abdeb7feb6c0afe72c2a460803cdfd" }, "downloads": -1, "filename": "parameterized-0.5.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "22576412f8c6e2f9cbea3ddf4ec61dff", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 15243, "upload_time": "2016-08-02T16:24:10", "url": "https://files.pythonhosted.org/packages/8c/83/c3634ace68dc1b49a1eb4a16513818f921019ad5cc3830f000a1553a116c/parameterized-0.5.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e1c1b61c7c87650258660a094bd2ae51", "sha256": "783069d1abc199f2c1c56d4b976f4f6df8848497e5f5dba5d47ad238e5e3ae59" }, "downloads": -1, "filename": "parameterized-0.5.0.tar.gz", "has_sig": false, "md5_digest": "e1c1b61c7c87650258660a094bd2ae51", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11167, "upload_time": "2016-08-02T16:24:08", "url": "https://files.pythonhosted.org/packages/1b/31/7802c3fc3a8b0f62faa36190f65b3f960987c20cd09795df35762796b823/parameterized-0.5.0.tar.gz" } ], "0.6.1": [ { "comment_text": "", "digests": { "md5": "6cfbd1449971a8ec5caa4a171f367815", "sha256": "cf5fa4f295dfb823cebdb27a00566113f2fbb71c7d5ca7b7a1019fd20c8a0811" }, "downloads": -1, "filename": "parameterized-0.6.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "6cfbd1449971a8ec5caa4a171f367815", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 23029, "upload_time": "2017-03-21T17:19:11", "url": "https://files.pythonhosted.org/packages/65/d4/b0b626eb263a4c2aa3ca3cd20ea3db410db837f7f6b5d3fc4a6c4bee3631/parameterized-0.6.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e9dd0c5bf470fbaf92416e9165ea196c", "sha256": "caf58e717097735de0d7e15386a46ffa5ce25bb6a13a43716a8854a8d34841e2" }, "downloads": -1, "filename": "parameterized-0.6.1.tar.gz", "has_sig": false, "md5_digest": "e9dd0c5bf470fbaf92416e9165ea196c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14053, "upload_time": "2017-03-21T17:19:09", "url": "https://files.pythonhosted.org/packages/77/b6/8c481344c63b3eadeaa26f62b9d7ce4221a52bad390da5f059573d4c7ee4/parameterized-0.6.1.tar.gz" } ], "0.6.3": [ { "comment_text": "", "digests": { "md5": "1e61d4d8251c4aa73eb301f50bd1595b", "sha256": "938a66ba54f74671aeebf7ecf48e9da006c0e9b0e9502accef27e39a18f956c2" }, "downloads": -1, "filename": "parameterized-0.6.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "1e61d4d8251c4aa73eb301f50bd1595b", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 23106, "upload_time": "2019-01-22T17:40:43", "url": "https://files.pythonhosted.org/packages/3a/49/75f6dadb09e2f8ace3cdffe0c99a04f1b98dff41fbf9e768665d8b469e29/parameterized-0.6.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fd3a554efa6b1166a3bc2ec7ea65a8e4", "sha256": "e0cfe0cd293d9466aa0dd75cb0ca71f5a613bfa2c572652560c602a1e23ee0da" }, "downloads": -1, "filename": "parameterized-0.6.3.tar.gz", "has_sig": false, "md5_digest": "fd3a554efa6b1166a3bc2ec7ea65a8e4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20107, "upload_time": "2019-01-22T17:40:41", "url": "https://files.pythonhosted.org/packages/05/4f/1a68e90b6c1e3f7fea2c7549110a220c7e79b854eb5220e50bc1b0eed3d1/parameterized-0.6.3.tar.gz" } ], "0.7.0": [ { "comment_text": "", "digests": { "md5": "5fe68a7bc1cde15f7a73bf86c2f31c37", "sha256": "020343a281efcfe9b71b9028a91817f981202c14d72104b5a2fbe401dee25a18" }, "downloads": -1, "filename": "parameterized-0.7.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5fe68a7bc1cde15f7a73bf86c2f31c37", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 23550, "upload_time": "2019-02-06T03:43:36", "url": "https://files.pythonhosted.org/packages/d6/9b/5830b778f213ada36528d1c54fdc0a67178e6edd7c44ed59074851ebb2e7/parameterized-0.7.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a4c7408fffd7a16c2c0695dc8d588372", "sha256": "d8c8837fb677ed2d5a93b9e2308ce0da3aeb58cf513120d501e0b7af14da78d5" }, "downloads": -1, "filename": "parameterized-0.7.0.tar.gz", "has_sig": false, "md5_digest": "a4c7408fffd7a16c2c0695dc8d588372", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20751, "upload_time": "2019-02-06T03:43:34", "url": "https://files.pythonhosted.org/packages/f0/b6/f5ff739d20fca065a7632916765bb2ec02f04217de25e18982876c310b09/parameterized-0.7.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5fe68a7bc1cde15f7a73bf86c2f31c37", "sha256": "020343a281efcfe9b71b9028a91817f981202c14d72104b5a2fbe401dee25a18" }, "downloads": -1, "filename": "parameterized-0.7.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5fe68a7bc1cde15f7a73bf86c2f31c37", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 23550, "upload_time": "2019-02-06T03:43:36", "url": "https://files.pythonhosted.org/packages/d6/9b/5830b778f213ada36528d1c54fdc0a67178e6edd7c44ed59074851ebb2e7/parameterized-0.7.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a4c7408fffd7a16c2c0695dc8d588372", "sha256": "d8c8837fb677ed2d5a93b9e2308ce0da3aeb58cf513120d501e0b7af14da78d5" }, "downloads": -1, "filename": "parameterized-0.7.0.tar.gz", "has_sig": false, "md5_digest": "a4c7408fffd7a16c2c0695dc8d588372", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20751, "upload_time": "2019-02-06T03:43:34", "url": "https://files.pythonhosted.org/packages/f0/b6/f5ff739d20fca065a7632916765bb2ec02f04217de25e18982876c310b09/parameterized-0.7.0.tar.gz" } ] }