Skip to content

Commit 9742da0

Browse files
author
Sylvain MARIE
committed
Fixed issue happening with @pytest.mark.parametrize with python 2. Fixed #62
1 parent 49429af commit 9742da0

File tree

7 files changed

+34
-12
lines changed

7 files changed

+34
-12
lines changed

pytest_cases/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from distutils.version import LooseVersion
77
from warnings import warn
88

9+
from six import string_types
910
import pytest
1011

1112

@@ -76,7 +77,7 @@ def get_param_argnames_as_list(argnames):
7677
:param argnames:
7778
:return:
7879
"""
79-
if isinstance(argnames, str):
80+
if isinstance(argnames, string_types):
8081
argnames = argnames.replace(' ', '').split(',')
8182
return list(argnames)
8283

pytest_cases/main_fixtures.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from decopatch import function_decorator, DECORATED
1111
from makefun import with_signature, add_signature_parameters, remove_signature_parameters, wraps
1212

13+
from six import string_types
1314
import pytest
1415

1516
try: # python 3.3+
@@ -93,7 +94,7 @@ def _unpack_fixture(caller_module, argnames, fixture):
9394
argnames_lst = get_param_argnames_as_list(argnames)
9495

9596
# possibly get the source fixture name if the fixture symbol was provided
96-
if not isinstance(fixture, str):
97+
if not isinstance(fixture, string_types):
9798
source_f_name = get_fixture_name(fixture)
9899
scope = get_fixture_scope(fixture)
99100
else:
@@ -846,7 +847,7 @@ def _fixture_union(caller_module, name, fixtures, idstyle, scope="function", ids
846847
f_names = []
847848
for f in fixtures:
848849
# possibly get the fixture name if the fixture symbol was provided
849-
f_names.append(get_fixture_name(f) if not isinstance(f, str) else f)
850+
f_names.append(get_fixture_name(f) if not isinstance(f, string_types) else f)
850851

851852
if len(f_names) < 1:
852853
raise ValueError("Empty fixture unions are not permitted")
@@ -916,7 +917,7 @@ def _fixture_product(caller_module, name, fixtures_or_values, fixture_positions,
916917
# possibly get the fixture name if the fixture symbol was provided
917918
f = fixtures_or_values[f_pos]
918919
# and remember the position in the tuple
919-
f_names[f_pos] = get_fixture_name(f) if not isinstance(f, str) else f
920+
f_names[f_pos] = get_fixture_name(f) if not isinstance(f, string_types) else f
920921

921922
# remove duplicates by making it an ordered set
922923
all_names = remove_duplicates((n for n in f_names if n is not None))

pytest_cases/main_params.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from decopatch import function_decorator, DECORATED, with_parenthesis
1010

11-
import six
11+
from six import with_metaclass, string_types
1212
import pytest
1313

1414
try: # python 3.3+
@@ -41,7 +41,7 @@
4141
from pytest_cases.common import make_marked_parameter_value, get_pytest_marks_on_function
4242

4343

44-
class CaseDataGetter(six.with_metaclass(ABCMeta)):
44+
class CaseDataGetter(with_metaclass(ABCMeta)):
4545
"""
4646
A proxy for a test case. Instances of this class are created by `@cases_data` or `get_all_cases`.
4747
@@ -398,7 +398,7 @@ def _get_case_getter_s(f,
398398

399399
names, param_ids, all_param_values_combinations = gen
400400

401-
if isinstance(names, str):
401+
if isinstance(names, string_types):
402402
# then this is a string formatter creating the names. Create the corresponding callable
403403
_formatter = names
404404
def names(**params):

pytest_cases/plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from warnings import warn
55

66
from functools import partial
7+
from six import string_types
78

89
import pytest
910

@@ -629,7 +630,7 @@ def parametrize(metafunc, argnames, argvalues, indirect=False, ids=None, scope=N
629630

630631
# detect union fixtures
631632
if is_fixture_union_params(argvalues):
632-
if ',' in argnames or not isinstance(argnames, str):
633+
if ',' in argnames or not isinstance(argnames, string_types):
633634
raise ValueError("Union fixtures can not be parametrized")
634635
union_fixture_name = argnames
635636
union_fixture_alternatives = argvalues

pytest_cases/tests/fixtures/test_fixtures_parametrize_stereo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from distutils.version import LooseVersion
22
from itertools import product
33

4+
from six import string_types
45
import pytest
56

67
from pytest_cases import pytest_fixture_plus
@@ -47,7 +48,7 @@ def stereo_cfg(path, cfg_factory, request):
4748
As opposed to `stereo_cfg_2`, we use here two @parametrize decorators.
4849
We check that the execution order is correct.
4950
"""
50-
assert isinstance(path, str)
51+
assert isinstance(path, string_types)
5152
assert isinstance(cfg_factory, type)
5253
a.assert_state_and_move(path=path, cfg_factory=cfg_factory)
5354
return "hello"
@@ -95,7 +96,7 @@ def stereo_cfg_2(path, request, cfg_factory):
9596
`product(CFG_TYPES, STEREO_PATHS)` and a single call to parametrize is made.
9697
We check that the execution order is the same.
9798
"""
98-
assert isinstance(path, str)
99+
assert isinstance(path, string_types)
99100
assert isinstance(cfg_factory, type)
100101

101102
c.assert_state_and_move(path=path, cfg_factory=cfg_factory)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
From https://github.com/smarie/python-pytest-cases/issues/62
3+
"""
4+
from __future__ import unicode_literals
5+
import pytest
6+
from typing import Text
7+
8+
9+
@pytest.fixture
10+
def my_cool_fixture():
11+
return Text('hello world')
12+
13+
14+
@pytest.mark.parametrize('object_id', ['a1', 'b2', 'b3'])
15+
def test_my_cool_feature_with_fixture(my_cool_fixture, object_id):
16+
print(my_cool_fixture)
17+
print(object_id)
18+
pass

pytest_cases/tests/meta/test_all.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from os.path import join, dirname, pardir, isdir, exists
99

1010
import pytest
11-
import six
11+
from six import string_types
1212

1313
# Make the list of all tests that we will have to execute (each in an independent pytest runner)
1414
THIS_DIR = dirname(__file__)
@@ -145,7 +145,7 @@ def real_prepare_config(args=None, plugins=None):
145145
elif isinstance(args, py.path.local):
146146
args = [str(args)]
147147
elif not isinstance(args, (tuple, list)):
148-
if not isinstance(args, str):
148+
if not isinstance(args, string_types):
149149
raise ValueError("not a string or argument list: %r" % (args,))
150150
args = shlex.split(args, posix=sys.platform != "win32")
151151
config = get_config()

0 commit comments

Comments
 (0)