Skip to content

Commit d50a873

Browse files
author
Sylvain MARIE
committed
Marks on cases are now also working with pytest 3.3. Fixed #23
1 parent 6a5c196 commit d50a873

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

pytest_cases/main.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,13 @@ def datasets_decorator(test_func):
514514

515515

516516
# Compatibility for the way we put marks on single parameters in the list passed to @pytest.mark.parametrize
517+
# see https://docs.pytest.org/en/3.3.0/skipping.html?highlight=mark%20parametrize#skip-xfail-with-parametrize
518+
517519
try:
518520
_ = pytest.param
519521
def get_marked_parameter_for_case(c, marks):
520-
return pytest.param(c, marks=marks, id=str(c))
522+
marks_mod = transform_marks_into_decorators(marks)
523+
return pytest.param(c, marks=marks_mod, id=str(c))
521524
except AttributeError:
522525
def get_marked_parameter_for_case(c, marks):
523526
if len(marks) > 1:
@@ -528,6 +531,20 @@ def get_marked_parameter_for_case(c, marks):
528531
return markinfodecorator(*markinfo.args)(c)
529532

530533

534+
def transform_marks_into_decorators(marks):
535+
"""
536+
Transforms the provided marks (MarkInfo) into MarkDecorator
537+
:param marks:
538+
:return:
539+
"""
540+
marks_mod = []
541+
for m in marks:
542+
md = pytest.mark.MarkDecorator()
543+
md.mark = m
544+
marks_mod.append(md)
545+
return marks_mod
546+
547+
531548
def get_all_cases(cases=None, # type: Union[Callable[[Any], Any], Iterable[Callable[[Any], Any]]]
532549
module=None, # type: Union[ModuleType, Iterable[ModuleType]]
533550
this_module_object=None, # type: Any

pytest_cases/tests/simple/test_pytest_marks.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

3-
from pytest_cases.main import get_pytest_marks_on_case_func, get_marked_parameter_for_case
3+
from pytest_cases.main import get_pytest_marks_on_case_func, get_marked_parameter_for_case, \
4+
transform_marks_into_decorators
45

56

67
@pytest.mark.skipif(True, reason="why")
@@ -15,7 +16,11 @@ def test_get_pytest_marks():
1516
"""
1617
# extract the marks from a case function
1718
marks = get_pytest_marks_on_case_func(case_func)
19+
# transform them into decorators
20+
marks = transform_marks_into_decorators(marks)
21+
# check that the mark is the same than a manually made one
1822
assert len(marks) == 1
23+
assert str(marks[0]) == str(pytest.mark.skipif(True, reason="why"))
1924

2025
# transform a parameter into a marked parameter
2126
dummy_case = (1, 2, 3)

0 commit comments

Comments
 (0)