Skip to content

Commit 9be81c4

Browse files
author
Sylvain MARIE
committed
Replaced LooseVersion usage in the tests with a simple hasattr
1 parent b1e21e2 commit 9be81c4

File tree

7 files changed

+29
-26
lines changed

7 files changed

+29
-26
lines changed

pytest_cases/tests/pytest_extension/fixtures/fixture_plus_and_others/test_fixtures_parametrize.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from distutils.version import LooseVersion
2-
3-
from pytest_cases import pytest_fixture_plus
41
import pytest
2+
from pytest_cases import pytest_fixture_plus
3+
4+
5+
has_pytest_param = hasattr(pytest, 'param')
56

67

78
@pytest_fixture_plus(scope="module")
@@ -27,7 +28,7 @@ def test_synthesis(module_results_dct):
2728

2829

2930
# pytest.param - not available in all versions
30-
if LooseVersion(pytest.__version__) < LooseVersion('3.2.0'):
31+
if not has_pytest_param:
3132
# with pytest < 3.2.0 we
3233
# - would have to merge all parametrize marks if we wish to pass a kwarg (here, ids)
3334
# - cannot use pytest.param as it is not taken into account

pytest_cases/tests/pytest_extension/fixtures/fixture_plus_and_others/test_fixtures_paramfixtures.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
from distutils.version import LooseVersion
2-
31
import pytest
42
from pytest_cases import param_fixture, param_fixtures, pytest_fixture_plus
53

64

75
# pytest.param - not available in all versions
8-
if LooseVersion(pytest.__version__) >= LooseVersion('3.0.0'):
6+
has_pytest_param = hasattr(pytest, 'param')
7+
if has_pytest_param:
98
pytest_param = pytest.param
109
else:
1110
def pytest_param(*args, **kwargs):
@@ -71,7 +70,7 @@ def test_custom_parameters(myfix, arg3, arg4, parg1, parg2, request):
7170
""""""
7271
assert myfix[2] == parg1
7372
paramvalues = request.node.nodeid.split('[')[1][:-1]
74-
if LooseVersion(pytest.__version__) >= LooseVersion('3.0.0'):
73+
if has_pytest_param:
7574
arg1arg2id = "f_a" if myfix[:-1] == (1, 2) else "f_b"
7675
arg3arg4id = "t_a" if (arg3, arg4) == (10, 20) else "t_b"
7776
else:
@@ -94,7 +93,7 @@ def test_synthesis(module_results_dct):
9493
'test_custom_parameters[f_b-c-d-t_a]',
9594
'test_custom_parameters[f_b-c-d-t_b]']
9695

97-
if LooseVersion(pytest.__version__) < LooseVersion('3.0.0'):
96+
if not has_pytest_param:
9897
end_list = [s.replace('t_a', '10-20')
9998
.replace('t_b', '30-40')
10099
.replace('f_a', '1-2')

pytest_cases/tests/pytest_extension/fixtures/fixture_plus_and_others/test_fixtures_paramfixtures_marks.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
from distutils.version import LooseVersion
2-
31
import pytest
4-
52
from pytest_cases import param_fixture
63

4+
has_pytest_param = hasattr(pytest, 'param')
5+
76
# pytest.param - not available in all versions
8-
if LooseVersion(pytest.__version__) >= LooseVersion('3.0.0'):
7+
if has_pytest_param:
98
a = param_fixture("a", [1,
109
pytest.param(2, id='22'),
1110
pytest.param(3, marks=pytest.mark.skip)

pytest_cases/tests/pytest_extension/fixtures/fixture_unions/test_fixture_union_custom_mark.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
from distutils.version import LooseVersion
2-
31
import pytest
4-
52
from pytest_cases import param_fixture, fixture_union
63

4+
has_pytest_param = hasattr(pytest, 'param')
5+
76
# pytest.param is not available in all versions
8-
if LooseVersion(pytest.__version__) >= LooseVersion('3.0.0'):
7+
if has_pytest_param:
98
a = param_fixture("a", [1,
109
pytest.param(2, id='22'),
1110
pytest.param(3, marks=pytest.mark.skip)

pytest_cases/tests/pytest_extension/fixtures/parametrize_plus_fixture_ref/test_fixture_ref_custom1.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
from distutils.version import LooseVersion
2-
31
import pytest
42

53
from pytest_harvest import saved_fixture, get_session_synthesis_dct
64
from pytest_cases import parametrize_plus, fixture_ref, pytest_fixture_plus
75

86

7+
has_pytest_param = hasattr(pytest, 'param')
8+
9+
910
# pytest.param is not available in all versions
10-
if LooseVersion(pytest.__version__) >= LooseVersion('3.0.0'):
11+
if has_pytest_param:
1112

1213
@pytest.fixture
1314
@saved_fixture

pytest_cases/tests/pytest_extension/fixtures/parametrize_plus_fixture_ref/test_fixture_ref_custom2.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from distutils.version import LooseVersion
2-
31
import pytest
42
from pytest_cases import parametrize_plus, fixture_ref
53

4+
5+
has_pytest_param = hasattr(pytest, 'param')
6+
7+
68
# pytest.param is not available in all versions
7-
if LooseVersion(pytest.__version__) >= LooseVersion('3.0.0'):
9+
if has_pytest_param:
810
@pytest.fixture
911
def a():
1012
return 'a'

pytest_cases/tests/pytest_extension/fixtures/parametrize_plus_fixture_ref/test_fixture_ref_custom3.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from distutils.version import LooseVersion
2-
31
import pytest
42
from pytest_cases import parametrize_plus, fixture_ref
53

4+
5+
has_pytest_param = hasattr(pytest, 'param')
6+
7+
68
# pytest.param is not available in all versions
7-
if LooseVersion(pytest.__version__) >= LooseVersion('3.0.0'):
9+
if has_pytest_param:
810
@pytest.fixture
911
def a():
1012
return 'a'

0 commit comments

Comments
 (0)