Skip to content

Commit

Permalink
Fixed issue happening with @pytest.mark.parametrize with python 2. F…
Browse files Browse the repository at this point in the history
…ixed #62
  • Loading branch information
Sylvain MARIE committed Oct 23, 2019
1 parent 49429af commit 9742da0
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 12 deletions.
3 changes: 2 additions & 1 deletion pytest_cases/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from distutils.version import LooseVersion
from warnings import warn

from six import string_types
import pytest


Expand Down Expand Up @@ -76,7 +77,7 @@ def get_param_argnames_as_list(argnames):
:param argnames:
:return:
"""
if isinstance(argnames, str):
if isinstance(argnames, string_types):
argnames = argnames.replace(' ', '').split(',')
return list(argnames)

Expand Down
7 changes: 4 additions & 3 deletions pytest_cases/main_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from decopatch import function_decorator, DECORATED
from makefun import with_signature, add_signature_parameters, remove_signature_parameters, wraps

from six import string_types
import pytest

try: # python 3.3+
Expand Down Expand Up @@ -93,7 +94,7 @@ def _unpack_fixture(caller_module, argnames, fixture):
argnames_lst = get_param_argnames_as_list(argnames)

# possibly get the source fixture name if the fixture symbol was provided
if not isinstance(fixture, str):
if not isinstance(fixture, string_types):
source_f_name = get_fixture_name(fixture)
scope = get_fixture_scope(fixture)
else:
Expand Down Expand Up @@ -846,7 +847,7 @@ def _fixture_union(caller_module, name, fixtures, idstyle, scope="function", ids
f_names = []
for f in fixtures:
# possibly get the fixture name if the fixture symbol was provided
f_names.append(get_fixture_name(f) if not isinstance(f, str) else f)
f_names.append(get_fixture_name(f) if not isinstance(f, string_types) else f)

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

# remove duplicates by making it an ordered set
all_names = remove_duplicates((n for n in f_names if n is not None))
Expand Down
6 changes: 3 additions & 3 deletions pytest_cases/main_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from decopatch import function_decorator, DECORATED, with_parenthesis

import six
from six import with_metaclass, string_types
import pytest

try: # python 3.3+
Expand Down Expand Up @@ -41,7 +41,7 @@
from pytest_cases.common import make_marked_parameter_value, get_pytest_marks_on_function


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

names, param_ids, all_param_values_combinations = gen

if isinstance(names, str):
if isinstance(names, string_types):
# then this is a string formatter creating the names. Create the corresponding callable
_formatter = names
def names(**params):
Expand Down
3 changes: 2 additions & 1 deletion pytest_cases/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from warnings import warn

from functools import partial
from six import string_types

import pytest

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

# detect union fixtures
if is_fixture_union_params(argvalues):
if ',' in argnames or not isinstance(argnames, str):
if ',' in argnames or not isinstance(argnames, string_types):
raise ValueError("Union fixtures can not be parametrized")
union_fixture_name = argnames
union_fixture_alternatives = argvalues
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from distutils.version import LooseVersion
from itertools import product

from six import string_types
import pytest

from pytest_cases import pytest_fixture_plus
Expand Down Expand Up @@ -47,7 +48,7 @@ def stereo_cfg(path, cfg_factory, request):
As opposed to `stereo_cfg_2`, we use here two @parametrize decorators.
We check that the execution order is correct.
"""
assert isinstance(path, str)
assert isinstance(path, string_types)
assert isinstance(cfg_factory, type)
a.assert_state_and_move(path=path, cfg_factory=cfg_factory)
return "hello"
Expand Down Expand Up @@ -95,7 +96,7 @@ def stereo_cfg_2(path, request, cfg_factory):
`product(CFG_TYPES, STEREO_PATHS)` and a single call to parametrize is made.
We check that the execution order is the same.
"""
assert isinstance(path, str)
assert isinstance(path, string_types)
assert isinstance(cfg_factory, type)

c.assert_state_and_move(path=path, cfg_factory=cfg_factory)
Expand Down
18 changes: 18 additions & 0 deletions pytest_cases/tests/issues/test_issue_python2_str.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""
From https://github.com/smarie/python-pytest-cases/issues/62
"""
from __future__ import unicode_literals
import pytest
from typing import Text


@pytest.fixture
def my_cool_fixture():
return Text('hello world')


@pytest.mark.parametrize('object_id', ['a1', 'b2', 'b3'])
def test_my_cool_feature_with_fixture(my_cool_fixture, object_id):
print(my_cool_fixture)
print(object_id)
pass
4 changes: 2 additions & 2 deletions pytest_cases/tests/meta/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from os.path import join, dirname, pardir, isdir, exists

import pytest
import six
from six import string_types

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

0 comments on commit 9742da0

Please sign in to comment.