Skip to content

Commit 8b95dcf

Browse files
author
Sylvain MARIE
committed
Fixed test for pytest < 3.2
1 parent 9ff46e1 commit 8b95dcf

File tree

1 file changed

+50
-47
lines changed

1 file changed

+50
-47
lines changed

pytest_cases/tests/fixtures/test_fixtures_parametrize.py

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33
from pytest_cases import pytest_fixture_plus
44
import pytest
55

6-
# pytest.param - not available in all versions
7-
if LooseVersion(pytest.__version__) >= LooseVersion('3.0.0'):
8-
pytest_param = pytest.param
9-
else:
10-
def pytest_param(*args, **kwargs):
11-
return args
12-
136

147
@pytest_fixture_plus(scope="module")
158
@pytest.mark.parametrize("arg1", ["one", "two"])
@@ -24,49 +17,59 @@ def test_one(myfix):
2417
print(myfix)
2518

2619

27-
@pytest_fixture_plus
28-
@pytest.mark.parametrize("arg3", [pytest_param(0, id='!0!')], ids=str)
29-
@pytest.mark.parametrize("arg1, arg2", [
30-
(1, 2),
31-
pytest_param(3, 4, id="p_a"),
32-
pytest_param(5, 6, id="skipped", marks=pytest.mark.skip)
33-
])
34-
def myfix2(arg1, arg2, arg3):
35-
return arg1, arg2, arg3
36-
37-
38-
def test_two(myfix2):
39-
assert myfix2 in {(1, 2, 0), (3, 4, 0), (5, 6, 0)}
40-
print(myfix2)
41-
42-
43-
@pytest_fixture_plus
44-
@pytest.mark.parametrize("arg1, arg2", [
45-
pytest_param(5, 6, id="a")
46-
], ids=['ignored_id'])
47-
def myfix3(arg1, arg2):
48-
return arg1, arg2
49-
50-
51-
def test_two(myfix2, myfix3):
52-
assert myfix2 in {(1, 2, 0), (3, 4, 0), (5, 6, 0)}
53-
print(myfix2)
54-
55-
5620
def test_synthesis(module_results_dct):
5721
"""Use pytest-harvest to check that the list of executed tests is correct """
5822

59-
if LooseVersion(pytest.__version__) >= LooseVersion('3.0.0'):
60-
id_of_last_tests = ['p_a', 'skipped']
61-
extra_test = []
62-
else:
63-
id_of_last_tests = ['3-4', '5-6']
64-
extra_test = ['test_two[%s-a]' % id_of_last_tests[1]]
65-
6623
assert list(module_results_dct) == ['test_one[one-one]',
6724
'test_one[one-two]',
6825
'test_one[two-one]',
69-
'test_one[two-two]',
70-
'test_two[1-2-!0!-a]',
71-
'test_two[%s-!0!-a]' % id_of_last_tests[0],
72-
] + extra_test
26+
'test_one[two-two]']
27+
28+
29+
# pytest.param - not available in all versions
30+
if LooseVersion(pytest.__version__) >= LooseVersion('3.0.0'):
31+
# with pytest < 3.2.0 we
32+
# - would have to merge all parametrize marks if we wish to pass a kwarg (here, ids)
33+
# - cannot use pytest.param as it is not taken into account
34+
# > no go
35+
36+
@pytest_fixture_plus
37+
@pytest.mark.parametrize("arg3", [pytest.param(0, id='!0!')], ids=str)
38+
@pytest.mark.parametrize("arg1, arg2", [
39+
(1, 2),
40+
pytest.param(3, 4, id="p_a"),
41+
pytest.param(5, 6, id="skipped", marks=pytest.mark.skip)
42+
])
43+
def myfix2(arg1, arg2, arg3):
44+
return arg1, arg2, arg3
45+
46+
47+
def test_two(myfix2):
48+
assert myfix2 in {(1, 2, 0), (3, 4, 0), (5, 6, 0)}
49+
print(myfix2)
50+
51+
52+
@pytest_fixture_plus
53+
@pytest.mark.parametrize("arg1, arg2", [
54+
pytest.param(5, 6, id="a")
55+
], ids=['ignored_id'])
56+
def myfix3(arg1, arg2):
57+
return arg1, arg2
58+
59+
60+
def test_three(myfix2, myfix3):
61+
assert myfix2 in {(1, 2, 0), (3, 4, 0), (5, 6, 0)}
62+
print(myfix2)
63+
64+
65+
def test_synthesis(module_results_dct):
66+
"""Use pytest-harvest to check that the list of executed tests is correct """
67+
68+
assert list(module_results_dct) == ['test_one[one-one]',
69+
'test_one[one-two]',
70+
'test_one[two-one]',
71+
'test_one[two-two]',
72+
'test_two[1-2-!0!]',
73+
'test_two[p_a-!0!]',
74+
'test_three[1-2-!0!-a]',
75+
'test_three[p_a-!0!-a]']

0 commit comments

Comments
 (0)