Skip to content

Instantly share code, notes, and snippets.

@curzona
Last active May 9, 2016 17:36
Show Gist options
  • Save curzona/1f0962448503ec35ea868d6ff52b4f5d to your computer and use it in GitHub Desktop.
Save curzona/1f0962448503ec35ea868d6ff52b4f5d to your computer and use it in GitHub Desktop.
test case parameterization with all pairs
C:\Users\adcurzon\Desktop\hello_allpairs>py.test test_allpairs.py -v -l --capture=no
============================= test session starts =============================
platform win32 -- Python 2.7.11, pytest-2.9.1, py-1.4.31, pluggy-0.3.1 -- c:\python27\python.exe
cachedir: .cache
rootdir: C:\Users\adcurzon\Desktop\hello_allpairs, inifile:
plugins: bdd-2.16.1, cov-1.6, instafail-0.2.0, ordering-0.3, pep8-1.0.5, random-0.2, repeater-0.1.0, timeout-1.0.0, xdist-1.14, teamcity-messages-1.8
collected 9 items
test_allpairs.py::test_foo[dodgers-2015-fenway park] PASSED
test_allpairs.py::test_foo[cubs-2016-fenway park] PASSED
test_allpairs.py::test_foo[redsocks-2016-dodger stadium] PASSED
test_allpairs.py::test_foo[redsocks-2015-wrigley field] PASSED
test_allpairs.py::test_foo[cubs-2015-dodger stadium] PASSED
test_allpairs.py::test_foo[dodgers-2016-wrigley field] PASSED
test_allpairs.py::test_foo[dodgers-2016-dodger stadium] PASSED
test_allpairs.py::test_foo[cubs-2016-wrigley field] PASSED
test_allpairs.py::test_foo[redsocks-2016-fenway park] PASSED
========================== 9 passed in 0.04 seconds ===========================
import itertools
import pytest
from metacomm.combinatorics.all_pairs2 import all_pairs2 as all_pairs
def pytest_generate_tests(metafunc):
if hasattr(metafunc.function, 'all_pairs'):
argnames, argvalues = getattr(getattr(metafunc.function, 'all_pairs'), 'args')
tuples = list(all_pairs(argvalues))
metafunc.parametrize(argnames, tuples)
@pytest.mark.all_pairs("team,year,stadium", [
["dodgers", "cubs", "redsocks"],
["2015", "2016"],
["fenway park", "dodger stadium", "wrigley field"]
])
def test_foo(team, year, stadium):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment