From ab005a4261927acbe96e2d76d5e0f6864cb51bd0 Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Wed, 8 Oct 2014 00:11:32 +0100 Subject: [PATCH] Functional tests for id function --HG-- branch : issue351 --- testing/python/integration.py | 55 ++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/testing/python/integration.py b/testing/python/integration.py index e27f27d52..b01efa522 100644 --- a/testing/python/integration.py +++ b/testing/python/integration.py @@ -262,5 +262,58 @@ class TestNoselikeTestAttribute: call = reprec.getcalls("pytest_collection_modifyitems")[0] assert len(call.items) == 1 assert call.items[0].cls.__name__ == "TC" - + +@pytest.mark.issue351 +class TestParameterize: + + def test_idfn_marker(self, testdir): + testdir.makepyfile(""" + import pytest + + def idfn(param): + if param == 0: + return 'spam' + elif param == 1: + return 'ham' + else: + return None + + @pytest.mark.parametrize('a,b', [(0, 2), (1, 2)], ids=idfn) + def test_params(a, b): + pass + """) + res = testdir.runpytest('--collect-only') + res.stdout.fnmatch_lines([ + "*spam-2*", + "*ham-2*", + ]) + + def test_idfn_fixture(self, testdir): + testdir.makepyfile(""" + import pytest + + def idfn(param): + if param == 0: + return 'spam' + elif param == 1: + return 'ham' + else: + return None + + @pytest.fixture(params=[0, 1], ids=idfn) + def a(request): + return request.param + + @pytest.fixture(params=[1, 2], ids=idfn) + def b(request): + return request.param + + def test_params(a, b): + pass + """) + res = testdir.runpytest('--collect-only') + res.stdout.fnmatch_lines([ + "*spam-2*", + "*ham-2*", + ])