Skip to content

Commit 6046df0

Browse files
author
Sylvain MARIE
committed
Fixed test for pytest 2.x
1 parent f103d3c commit 6046df0

File tree

1 file changed

+42
-14
lines changed

1 file changed

+42
-14
lines changed

pytest_cases/tests/simple/test_paramfixtures.py

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
from distutils.version import LooseVersion
2+
13
import pytest
24
from pytest_cases import param_fixture, param_fixtures, pytest_fixture_plus
35

6+
7+
# pytest.param - not available in all versions
8+
if LooseVersion(pytest.__version__) >= LooseVersion('3.0.0'):
9+
pytest_param = pytest.param
10+
else:
11+
def pytest_param(*args, **kwargs):
12+
return args
13+
14+
415
# create a single parameter fixture
516
my_parameter = param_fixture("my_parameter", [1, 2, 3, 4])
617

@@ -39,42 +50,59 @@ def test_uses_param2(arg1, arg2, fixture_uses_param2):
3950

4051
@pytest_fixture_plus
4152
@pytest.mark.parametrize("arg1, arg2", [
42-
pytest.param(1, 2, id="f_a"),
43-
pytest.param(3, 4, id="f_b")
53+
pytest_param(1, 2, id="f_a"),
54+
pytest_param(3, 4, id="f_b")
4455
])
4556
def myfix(arg1, arg2, parg1):
4657
"""One parameterized fixture relying on above param fixture"""
4758
return arg1, arg2, parg1
4859

4960

5061
@pytest.mark.parametrize("arg3, arg4", [
51-
pytest.param(10, 20, id="t_a"),
52-
pytest.param(30, 40, id="t_b")
62+
pytest_param(10, 20, id="t_a"),
63+
pytest_param(30, 40, id="t_b")
5364
])
5465
def test_one(myfix, arg3, arg4, parg1, parg2, request):
5566
""""""
5667
assert myfix[2] == parg1
5768
paramvalues = request.node.nodeid.split('[')[1][:-1]
58-
arg1arg2id = "f_a" if myfix[:-1] == (1, 2) else "f_b"
59-
arg3arg4id = "t_a" if (arg3, arg4) == (10, 20) else "t_b"
69+
if LooseVersion(pytest.__version__) >= LooseVersion('3.0.0'):
70+
arg1arg2id = "f_a" if myfix[:-1] == (1, 2) else "f_b"
71+
arg3arg4id = "t_a" if (arg3, arg4) == (10, 20) else "t_b"
72+
else:
73+
arg1arg2id = "-".join(["%s" % v for v in myfix[:-1]])
74+
arg3arg4id = "-".join(["%s" % v for v in (arg3, arg4)])
75+
6076
assert paramvalues == "{}-{}-{}-{}".format(arg1arg2id, parg1, parg2, arg3arg4id)
6177
# print("parg1={} parg2={} myfix={} arg3={} arg4={}".format(parg1, parg2, myfix, arg3, arg4))
6278

6379

6480
def test_synthesis(module_results_dct):
6581
"""Use pytest-harvest to check that the list of executed tests is correct """
6682

83+
if LooseVersion(pytest.__version__) >= LooseVersion('3.0.0'):
84+
end_list = ['test_one[f_a-a-b-t_a]',
85+
'test_one[f_a-a-b-t_b]',
86+
'test_one[f_a-c-d-t_a]',
87+
'test_one[f_a-c-d-t_b]',
88+
'test_one[f_b-a-b-t_a]',
89+
'test_one[f_b-a-b-t_b]',
90+
'test_one[f_b-c-d-t_a]',
91+
'test_one[f_b-c-d-t_b]']
92+
else:
93+
end_list = [ 'test_one[1-2-a-b-10-20]',
94+
'test_one[1-2-a-b-30-40]',
95+
'test_one[1-2-c-d-10-20]',
96+
'test_one[1-2-c-d-30-40]',
97+
'test_one[3-4-a-b-10-20]',
98+
'test_one[3-4-a-b-30-40]',
99+
'test_one[3-4-c-d-10-20]',
100+
'test_one[3-4-c-d-30-40]']
101+
67102
assert list(module_results_dct) == ['test_uses_param[1]',
68103
'test_uses_param[2]',
69104
'test_uses_param[3]',
70105
'test_uses_param[4]',
71106
'test_uses_param2[1-2]',
72107
'test_uses_param2[3-4]',
73-
'test_one[f_a-a-b-t_a]',
74-
'test_one[f_a-a-b-t_b]',
75-
'test_one[f_a-c-d-t_a]',
76-
'test_one[f_a-c-d-t_b]',
77-
'test_one[f_b-a-b-t_a]',
78-
'test_one[f_b-a-b-t_b]',
79-
'test_one[f_b-c-d-t_a]',
80-
'test_one[f_b-c-d-t_b]']
108+
] + end_list

0 commit comments

Comments
 (0)