Skip to content

Commit 2c50f4c

Browse files
fix #3605 - unpack markdecorators from parameterization
1 parent d2953b6 commit 2c50f4c

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

changelog/3605.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
unpack marks from parameterization to prevent the markdecorator missmatch bug.

src/_pytest/mark/structures.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,12 @@ def get_unpacked_marks(obj):
221221
obtain the unpacked marks that are stored on an object
222222
"""
223223
mark_list = getattr(obj, "pytestmark", [])
224-
225224
if not isinstance(mark_list, list):
226225
mark_list = [mark_list]
226+
return normalize_mark_list(mark_list)
227+
228+
229+
def normalize_mark_list(mark_list):
227230
return [getattr(mark, "mark", mark) for mark in mark_list] # unpack MarkDecorator
228231

229232

src/_pytest/python.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@
3939
get_default_arg_names,
4040
)
4141
from _pytest.outcomes import fail
42-
from _pytest.mark.structures import transfer_markers, get_unpacked_marks
42+
from _pytest.mark.structures import (
43+
transfer_markers,
44+
get_unpacked_marks,
45+
normalize_mark_list,
46+
)
4347

4448

4549
# relative paths that we use to filter traceback entries from appearing to the user;
@@ -776,7 +780,7 @@ def setmulti2(self, valtypes, argnames, valset, id, marks, scopenum, param_index
776780
self.indices[arg] = param_index
777781
self._arg2scopenum[arg] = scopenum
778782
self._idlist.append(id)
779-
self.marks.extend(marks)
783+
self.marks.extend(normalize_mark_list(marks))
780784

781785
def setall(self, funcargs, id, param):
782786
for x in funcargs:
@@ -1255,7 +1259,7 @@ def __init__(
12551259
# feel free to cry, this was broken for years before
12561260
# and keywords cant fix it per design
12571261
self.keywords[mark.name] = mark
1258-
self.own_markers.extend(callspec.marks)
1262+
self.own_markers.extend(normalize_mark_list(callspec.marks))
12591263
if keywords:
12601264
self.keywords.update(keywords)
12611265

testing/test_mark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,4 +1170,4 @@ def test_custom_mark_parametrized(obj_type):
11701170
)
11711171

11721172
result = testdir.runpytest()
1173-
result.assert_outcomes(failed=0)
1173+
result.assert_outcomes(passed=4)

0 commit comments

Comments
 (0)