Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

pytest plugin: avoid repeating arguments in parametrize

Project Description
`pytest` plugin: avoid repeating arguments in `parametrize`
===========================================================

This is an alternative to the rejected pull request
`#780 <https://github.com/pytest-dev/pytest/pull/780>`__ of
`pytest <http://docs.pytest.org/>`__.

Installation
------------

Just get it from `PyPI <https://pypi.org/project/pytest-auto-parametrize>`__::

python3 -m pip install pytest-auto-parametrize --user

Usage
-----

This is an example for the usage of a `parametrized test`__ without using this
plugin:

__ http://docs.pytest.org/en/latest/parametrize.html

.. code:: python

import pytest

testparams = [
(1, 2, 3, 4, 5, 6, 7),
(7, 6, 5, 4, 3, 2, 1),
]

@pytest.mark.parametrize('a, b, c, d, e, f, g', testparams)
def test_many_args(a, b, c, d, e, f, g):
assert d == 4

The argument list has to be repeated, which is annoying.

By using this plugin, the repetition can be avoided:

.. code:: python

import pytest

testparams = [
(1, 2, 3, 4, 5, 6, 7),
(7, 6, 5, 4, 3, 2, 1),
]

@pytest.auto_parametrize(testparams)
def test_many_args(a, b, c, d, e, f, g):
assert d == 4

The auto-deduced parameters must be in the beginning of the parameter list, but
any other parameters can be used afterwards, e.g. fixtures:

.. code:: python

import pytest

testparams = [
(1, 2, 3, 4, 5, 6, 7),
(7, 6, 5, 4, 3, 2, 1),
]

@pytest.fixture
def myfixture():
return 4

@pytest.auto_parametrize(testparams)
def test_many_args_and_fixture(a, b, c, d, e, f, g, myfixture):
assert d - myfixture == 0

Limitations
-----------

Unlike ``@pytest.mark.parametrize(...)`` the decorator
``@pytest.auto_parametrize(...)`` cannot be used multiple times for the same
test function. It can be used together with one or multiple instances of
``@pytest.mark.parametrize(...)``, though, as long as the "auto" arguments are
in the beginning of the argument list.


Release History

Release History

This version
History Node

0.1.0

History Node

0.0.0

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
pytest_auto_parametrize-0.1.0-py2.py3-none-any.whl (4.9 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel Oct 2, 2016
pytest-auto-parametrize-0.1.0.tar.gz (2.7 kB) Copy SHA256 Checksum SHA256 Source Oct 2, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting