*unittest_expander* is a Python library that provides flexible and
easy-to-use tools to parametrize your unit tests, especially (but
not limited to) those based on *unittest.TestCase*.
The library is compatible with Python 3.11, 3.10, 3.9, 3.8, 3.7, 3.6 and
2.7, and does not depend on any external packages (i.e., uses only the
Python standard library).
:Authors: `Jan Kaliszewski (zuo)`_ and `others...`_
:License: `MIT License`_
:Home Page: https://github.com/zuo/unittest_expander
:Documentation: https://unittest-expander.readthedocs.io/en/stable/
.. _Jan Kaliszewski (zuo): https://github.com/zuo/
.. _others...: https://github.com/zuo/unittest_expander/pulls?q=is%3Apr+is%3Amerged
.. _MIT License: https://github.com/zuo/unittest_expander/blob/main/LICENSE.txt
Installing
----------
The easiest way to install the library is to execute (preferably in a
`virtualenv`_) the command::
python -m pip install unittest_expander
(note that you need network access to do it this way). If you do not
have the *pip* tool installed -- see:
https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
Alternatively, you can `download`_ the library source archive, unpack
it, ``cd`` to the unpacked directory and execute (preferably in a
`virtualenv`_) the following command::
python -m pip install .
Note: you may need to have administrator privileges if you do *not*
operate in a *virtualenv*.
It is also possible to use the library without installing it: as its
code is contained in a single file (``unittest_expander.py``), you can
just copy it into your project.
.. _virtualenv: https://packaging.python.org/tutorials/installing-packages/#creating-and-using-virtual-environments
.. _download: https://pypi.org/project/unittest_expander/#files
Usage example
-------------
Consider the following **ugly** test:
.. code:: python
import unittest
class Test(unittest.TestCase):
def test_sum(self):
for iterable, expected in [
([], 0),
([0], 0),
([3], 3),
([1, 3, 1], 5),
(frozenset({1, 3}), 4),
({1:'a', 3:'b'}, 4),
]:
self.assertEqual(sum(iterable), expected)
Is it cool? **Not at all!** So let's improve it:
.. code:: python
import unittest
from unittest_expander import expand, foreach
@expand
class Test(unittest.TestCase):
@foreach(
([], 0),
([0], 0),
([3], 3),
([1, 3, 1], 5),
(frozenset({1, 3}), 4),
({1:'a', 3:'b'}, 4),
)
def test_sum(self, iterable, expected):
self.assertEqual(sum(iterable), expected)
Now you have **6 distinct tests** (properly *isolated* and being
always *reported as separate tests*), although they share the same
test method source.
You may want to do the same in a bit more verbose and descriptive
way:
.. code:: python
import unittest
from unittest_expander import expand, foreach, param
@expand
class Test(unittest.TestCase):
test_sum_params = [
param([], expected=0).label('empty gives 0'),
param([0], expected=0),
param([3], expected=3),
param([1, 3, 1], expected=5),
param(frozenset({1, 3}), expected=4),
param({1:'a', 3:'b'}, expected=4).label('even dict is ok'),
]
@foreach(test_sum_params)
def test_sum(self, iterable, expected):
self.assertEqual(sum(iterable), expected)
This is only a fraction of the possibilities *unittest_expander*
offers to you.
You can **learn more** from the actual `documentation of the module
<https://unittest-expander.readthedocs.io/en/stable/narrative_documentation.html>`_.
Raw data
{
"_id": null,
"home_page": "https://github.com/zuo/unittest_expander",
"name": "unittest-expander",
"maintainer": "Jan Kaliszewski (zuo)",
"docs_url": null,
"requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7",
"maintainer_email": "zuo@kaliszewski.net",
"keywords": "unittest,testing,parametrization,parameterization",
"author": "Jan Kaliszewski (zuo) and others...",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/b5/08/bbc507df0b6d84c410d5fe809b5b8288987302542448addc55aced5ce14c/unittest_expander-0.4.4.tar.gz",
"platform": null,
"description": "*unittest_expander* is a Python library that provides flexible and\neasy-to-use tools to parametrize your unit tests, especially (but\nnot limited to) those based on *unittest.TestCase*.\n\nThe library is compatible with Python 3.11, 3.10, 3.9, 3.8, 3.7, 3.6 and\n2.7, and does not depend on any external packages (i.e., uses only the\nPython standard library).\n\n:Authors: `Jan Kaliszewski (zuo)`_ and `others...`_\n:License: `MIT License`_\n:Home Page: https://github.com/zuo/unittest_expander\n:Documentation: https://unittest-expander.readthedocs.io/en/stable/\n\n.. _Jan Kaliszewski (zuo): https://github.com/zuo/\n.. _others...: https://github.com/zuo/unittest_expander/pulls?q=is%3Apr+is%3Amerged\n.. _MIT License: https://github.com/zuo/unittest_expander/blob/main/LICENSE.txt\n\n\nInstalling\n----------\n\nThe easiest way to install the library is to execute (preferably in a\n`virtualenv`_) the command::\n\n python -m pip install unittest_expander\n\n(note that you need network access to do it this way). If you do not\nhave the *pip* tool installed -- see:\nhttps://packaging.python.org/guides/installing-using-pip-and-virtual-environments/\n\nAlternatively, you can `download`_ the library source archive, unpack\nit, ``cd`` to the unpacked directory and execute (preferably in a\n`virtualenv`_) the following command::\n\n python -m pip install .\n\nNote: you may need to have administrator privileges if you do *not*\noperate in a *virtualenv*.\n\nIt is also possible to use the library without installing it: as its\ncode is contained in a single file (``unittest_expander.py``), you can\njust copy it into your project.\n\n.. _virtualenv: https://packaging.python.org/tutorials/installing-packages/#creating-and-using-virtual-environments\n\n.. _download: https://pypi.org/project/unittest_expander/#files\n\n\nUsage example\n-------------\n\nConsider the following **ugly** test:\n\n.. code:: python\n\n import unittest\n\n class Test(unittest.TestCase):\n def test_sum(self):\n for iterable, expected in [\n ([], 0),\n ([0], 0),\n ([3], 3),\n ([1, 3, 1], 5),\n (frozenset({1, 3}), 4),\n ({1:'a', 3:'b'}, 4),\n ]:\n self.assertEqual(sum(iterable), expected)\n\nIs it cool? **Not at all!** So let's improve it:\n\n.. code:: python\n\n import unittest\n from unittest_expander import expand, foreach\n\n @expand\n class Test(unittest.TestCase):\n @foreach(\n ([], 0),\n ([0], 0),\n ([3], 3),\n ([1, 3, 1], 5),\n (frozenset({1, 3}), 4),\n ({1:'a', 3:'b'}, 4),\n )\n def test_sum(self, iterable, expected):\n self.assertEqual(sum(iterable), expected)\n\nNow you have **6 distinct tests** (properly *isolated* and being\nalways *reported as separate tests*), although they share the same\ntest method source.\n\nYou may want to do the same in a bit more verbose and descriptive\nway:\n\n.. code:: python\n\n import unittest\n from unittest_expander import expand, foreach, param\n\n @expand\n class Test(unittest.TestCase):\n\n test_sum_params = [\n param([], expected=0).label('empty gives 0'),\n param([0], expected=0),\n param([3], expected=3),\n param([1, 3, 1], expected=5),\n param(frozenset({1, 3}), expected=4),\n param({1:'a', 3:'b'}, expected=4).label('even dict is ok'),\n ]\n\n @foreach(test_sum_params)\n def test_sum(self, iterable, expected):\n self.assertEqual(sum(iterable), expected)\n\nThis is only a fraction of the possibilities *unittest_expander*\noffers to you.\n\nYou can **learn more** from the actual `documentation of the module\n<https://unittest-expander.readthedocs.io/en/stable/narrative_documentation.html>`_.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Easy and flexible unit test parametrization",
"version": "0.4.4",
"split_keywords": [
"unittest",
"testing",
"parametrization",
"parameterization"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f101f9afa126bbc02c1aa52c19b2094a753a826b822e674476a3a7998f1a6001",
"md5": "888a2a9e9fcd21ae25139d3c0f305221",
"sha256": "c316b068e1af9e84c6f48ce21901fe618c11042c5ec4fcefe633c0dad0b7f3d7"
},
"downloads": -1,
"filename": "unittest_expander-0.4.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "888a2a9e9fcd21ae25139d3c0f305221",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7",
"size": 26996,
"upload_time": "2023-03-21T21:25:06",
"upload_time_iso_8601": "2023-03-21T21:25:06.850345Z",
"url": "https://files.pythonhosted.org/packages/f1/01/f9afa126bbc02c1aa52c19b2094a753a826b822e674476a3a7998f1a6001/unittest_expander-0.4.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b508bbc507df0b6d84c410d5fe809b5b8288987302542448addc55aced5ce14c",
"md5": "25d078fbfb917041e238aa6178cf29dc",
"sha256": "dd35e170d3ad9a5c6e8eeff716db80c98cf5d682d18081c14e438b0f8f15d1a8"
},
"downloads": -1,
"filename": "unittest_expander-0.4.4.tar.gz",
"has_sig": false,
"md5_digest": "25d078fbfb917041e238aa6178cf29dc",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,>=2.7",
"size": 44383,
"upload_time": "2023-03-21T21:25:08",
"upload_time_iso_8601": "2023-03-21T21:25:08.627472Z",
"url": "https://files.pythonhosted.org/packages/b5/08/bbc507df0b6d84c410d5fe809b5b8288987302542448addc55aced5ce14c/unittest_expander-0.4.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-21 21:25:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "zuo",
"github_project": "unittest_expander",
"travis_ci": true,
"coveralls": false,
"github_actions": true,
"lcname": "unittest-expander"
}