Skip to content

Commit 0bcbd49

Browse files
author
Sylvain MARIE
committed
Marks set on a case class are now propagated to cases in the class. Fixes #139
1 parent 3167c47 commit 0bcbd49

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

pytest_cases/case_parametrizer_new.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,8 @@ def _of_interest(x): # noqa
603603
new_m.__name__ = m.__name__
604604
CaseInfo.copy_info(m, new_m)
605605
copy_pytest_marks(m, new_m, override=True)
606+
# also recopy all marks from the holding class to the function
607+
copy_pytest_marks(cls, new_m, override=False)
606608
m = new_m
607609
del new_m
608610

pytest_cases/common_pytest_marks.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,17 @@ def __init__(self, *args, **kwargs):
8181

8282
# ---------------- working on functions
8383
def copy_pytest_marks(from_f, to_f, override=False):
84-
"""Copy all pytest marks from a function to another"""
84+
"""Copy all pytest marks from a function or class to another"""
8585
from_marks = get_pytest_marks_on_function(from_f)
8686
to_marks = [] if override else get_pytest_marks_on_function(to_f)
87+
# note: the new marks are appended *after* existing if no override
8788
to_f.pytestmark = to_marks + from_marks
8889

8990

9091
def get_pytest_marks_on_function(f, as_decorators=False):
9192
"""
9293
Utility to return *ALL* pytest marks (not only parametrization) applied on a function
94+
Note that this also works on classes
9395
9496
:param f:
9597
:param as_decorators: transforms the marks into decorators before returning them

0 commit comments

Comments
 (0)