pytest-dynamic-parameterize
A powerful pytest plugin for Python projects, enabling dynamic test parameterization using functions.
Easily generate test parameters at runtime from any function—supporting advanced, data-driven, or config-based testing workflows.
🚀 Features
- ✅ Dynamic Parameterization: Generate test parameters dynamically by referencing a function.
- Use the
@pytest.mark.parametrize_func("function_name")marker on your test. - Supports both local and fully-qualified function names (e.g.,
my_funcormy_module.my_func). - Supports multiple
@pytest.mark.parametrize_funcmarkers on a single test for advanced parameterization. - Pass keyword arguments to your parameter function via the marker:
@pytest.mark.parametrize_func("my_params", some_param="some_value"). - Enables:
- Data-driven tests from config files, databases, or APIs
- Centralized test data logic
- Cleaner, more maintainable test code
- For skipped tests, for empty parameter sets, you can return
NOT_SET_PARAMETERSfrom your parameter function to indicate no parameters should be set.
- Use the
📦 Installation
pip install pytest-dynamic-parameterize
🔧 Usage
- Define a parameter function (must accept a
configargument and return a list of tuples or values):
# parameterize_functions.parametrize_functions.my_params.py
def my_params(config, some_param=None) -> list[tuple]:
if some_param == "special":
return [(10, 20, 30)]
return [
(1, 2, 3),
(4, 5, 9),
]
- Mark your test with one or more
@pytest.mark.parametrize_funcdecorators:
import pytest
from tests.parameterize_functions.my_params import my_params
@pytest.mark.parametrize_func("my_params")
def test_add(a, b, expected):
assert a + b == expected
-
Pass arguments to your parameter function:
import pytest from tests.parameterize_functions.my_params import my_params @pytest.mark.parametrize_func("my_params", some_param="special") def test_add_special(a, b, expected): assert a + b == expected
-
Use multiple parametrize_func markers for advanced parameterization:
import pytest from tests.parameterize_functions.my_params import my_params @pytest.mark.parametrize_func("my_params", some_param="special") @pytest.mark.parametrize_func("my_params") def test_add_multi(a1, b1, expected1, a2, b2, expected2): assert a1 + b1 == expected1 assert a2 + b2 == expected2
-
You can also use a fully-qualified function path:
import pytest @pytest.mark.parametrize_func("parameterize_functions.parametrize_functions.my_params") def test_add(a, b, expected): ...
-
The function can be imported or defined in the same module.
-
The function should return a list of argument tuples matching the test signature.
🤝 Contributing
If you have improvements, ideas, or bugfixes:
- Fork the repo
- Create a new branch
- Submit a pull request
I welcome additions that promote clean, productive, and maintainable development.
🙏 Thanks
Thanks for exploring this repository!
Happy testing!
Release files for pytest-dynamic-parameterize 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_dynamic_parameterize-1.2.0.tar.gz | 5.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_dynamic_parameterize-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.3 kB
Release files / pytest_dynamic_parameterize-1.2.0.tar.gz
| Download URL | pytest_dynamic_parameterize-1.2.0.tar.gz |
|---|---|
| Size | 5.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
187beba1d7a531257f9a8fe081fc28f3c946a0932a9e34611721414824a4d2e5
|
|
BLAKE2b-256 checksum How to use checksums |
8b0ee38c4e492d9ec01b367aa8568c01eddc6176ce4121e720da19bdea913bd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / pytest_dynamic_parameterize-1.2.0-py3-none-any.whl
| Download URL | pytest_dynamic_parameterize-1.2.0-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
343b25d6260756b4505bb5740ffaece553ec956373dfeeabec04bec85ab43317
|
|
BLAKE2b-256 checksum How to use checksums |
e9e123fc7dad0f1e1d885a19fecf5c89263c5b9fca277b66a2298eee67317ac5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|