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:
- License:
- Home Page:
- Documentation:
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.
Usage example
Consider the following ugly test:
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:
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:
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.
Metadata
Release files for unittest-expander 0.4.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| unittest_expander-0.4.4.tar.gz | 44.4 kB | Without provenance | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| unittest_expander-0.4.4-py3-none-any.whl | Python 3 | none | any | Details |
| unittest_expander-0.4.4-py2-none-any.whl | Python 2 | none | any | Details |
Total release size: 98.4 kB
Release files / unittest_expander-0.4.4.tar.gz
| Download URL | unittest_expander-0.4.4.tar.gz |
|---|---|
| Size | 44.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dd35e170d3ad9a5c6e8eeff716db80c98cf5d682d18081c14e438b0f8f15d1a8
|
|
BLAKE2b-256 checksum How to use checksums |
b508bbc507df0b6d84c410d5fe809b5b8288987302542448addc55aced5ce14c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Release files / unittest_expander-0.4.4-py3-none-any.whl
| Download URL | unittest_expander-0.4.4-py3-none-any.whl |
|---|---|
| Size | 27.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c316b068e1af9e84c6f48ce21901fe618c11042c5ec4fcefe633c0dad0b7f3d7
|
|
BLAKE2b-256 checksum How to use checksums |
f101f9afa126bbc02c1aa52c19b2094a753a826b822e674476a3a7998f1a6001
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Release files / unittest_expander-0.4.4-py2-none-any.whl
| Download URL | unittest_expander-0.4.4-py2-none-any.whl |
|---|---|
| Size | 27.0 kB |
| Tags | Python 2 |
|
SHA-256 checksum How to use checksums |
f306b71236516bafe23f955d3e19ee9891bf4717f1256952473ebca1bd011efc
|
|
BLAKE2b-256 checksum How to use checksums |
d5f82b3cbb412d9e97571ca17c20010a8e4713944d9e383a0dfe89c2c824b43b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.8.3 requests/2.27.1 setuptools/44.1.1 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/2.7.17
|
Security for unittest-expander 0.4.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.