Skip to main content

A pytest plugin to dynamically parameterize tests based on external data sources.

Project description

PyPI version Python Development Status Maintenance PyPI License


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_func or my_module.my_func).
    • Supports multiple @pytest.mark.parametrize_func markers 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_PARAMETERS from your parameter function to indicate no parameters should be set.

📦 Installation

pip install pytest-dynamic-parameterize

🔧 Usage

  1. Define a parameter function (must accept a config argument 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),
    ]
  1. Mark your test with one or more @pytest.mark.parametrize_func decorators:
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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_dynamic_parameterize-1.2.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_dynamic_parameterize-1.2.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest_dynamic_parameterize-1.2.0.tar.gz.

File metadata

File hashes

Hashes for pytest_dynamic_parameterize-1.2.0.tar.gz
Algorithm Hash digest
SHA256 187beba1d7a531257f9a8fe081fc28f3c946a0932a9e34611721414824a4d2e5
MD5 70de6f9f590c1a99b1eeb56b7014b41d
BLAKE2b-256 8b0ee38c4e492d9ec01b367aa8568c01eddc6176ce4121e720da19bdea913bd5

See more details on using hashes here.

File details

Details for the file pytest_dynamic_parameterize-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_dynamic_parameterize-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 343b25d6260756b4505bb5740ffaece553ec956373dfeeabec04bec85ab43317
MD5 46f6837f54a6574392d8810fe37a48fa
BLAKE2b-256 e9e123fc7dad0f1e1d885a19fecf5c89263c5b9fca277b66a2298eee67317ac5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page