Parameterized is a Python library that provides parameterized testing capabilities for various test frameworks like unittest, pytest, and nose. It simplifies writing data-driven tests by allowing the same test logic to be run with multiple sets of input data, reducing duplication and improving test coverage. The current version is 0.9.0, released in March 2023.
pip install parameterizedVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `parameterized` with Python's built-in `unittest` framework. It shows examples for parameterizing individual test methods using `@parameterized` and `@parameterized.expand`, and how to parameterize an entire test class using `@parameterized_class`.
Upgrade to Python 3.7+ or pin `parameterized` to version 0.8.1 or earlier.
Ensure `@mock.patch` is below `@parameterized` and mocked arguments are last in the function signature.
For very large datasets, consider generating test data on-the-fly within the test method itself, or exploring alternative parameterization methods suitable for streaming data if available within your test framework.
Always ensure you install `parameterized` (with the 'e') via `pip install parameterized`.
Keep test cases modular and focused. Break down complex scenarios into smaller, manageable tests. Each test should validate a specific aspect of functionality.
Replace `@parameterized` with `@parameterized.expand` when decorating test methods inside a `unittest.TestCase` subclass.
When parameterizing tests within a `unittest.TestCase` subclass, apply `@parameterized.expand` to the specific test method, rather than using `@parameterized` on the class itself.
Uninstall the wrong package (`pip uninstall parametrized`) and install the correct one (`pip install parameterized`).
Ensure you are using a recent version of the library (0.9.0 or later) and import it as `from parameterized import parameterized_class`. If the issue persists, explicitly import from the submodule `from parameterized.parameterized import parameterized_class` if the library structure changed or you are on an older version.
Install the library using pip: `pip install parameterized`.
Ensure that the `@mock.patch(...)` decorator is placed *below* the `@parameterized.expand(...)` decorator. Also, the mocked parameters must come last in the test method's signature.