Skip to content

Commit ef1b91b

Browse files
authored
Merge pull request #3606 from RonnyPfannschmidt/fix-3605
Fix 3605
2 parents f93995e + 643e5a9 commit ef1b91b

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

changelog/3605.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
no longer ValueError when using the ``get_marker`` api.

src/_pytest/mark/structures.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,18 @@ def get_unpacked_marks(obj):
225225
obtain the unpacked marks that are stored on an object
226226
"""
227227
mark_list = getattr(obj, "pytestmark", [])
228-
229228
if not isinstance(mark_list, list):
230229
mark_list = [mark_list]
230+
return normalize_mark_list(mark_list)
231+
232+
233+
def normalize_mark_list(mark_list):
234+
"""
235+
normalizes marker decorating helpers to mark objects
236+
237+
:type mark_list: List[Union[Mark, Markdecorator]]
238+
:rtype: List[Mark]
239+
"""
231240
return [getattr(mark, "mark", mark) for mark in mark_list] # unpack MarkDecorator
232241

233242

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;
@@ -773,7 +777,7 @@ def setmulti2(self, valtypes, argnames, valset, id, marks, scopenum, param_index
773777
self.indices[arg] = param_index
774778
self._arg2scopenum[arg] = scopenum
775779
self._idlist.append(id)
776-
self.marks.extend(marks)
780+
self.marks.extend(normalize_mark_list(marks))
777781

778782
def setall(self, funcargs, id, param):
779783
for x in funcargs:
@@ -1254,7 +1258,7 @@ def __init__(
12541258
# feel free to cry, this was broken for years before
12551259
# and keywords cant fix it per design
12561260
self.keywords[mark.name] = mark
1257-
self.own_markers.extend(callspec.marks)
1261+
self.own_markers.extend(normalize_mark_list(callspec.marks))
12581262
if keywords:
12591263
self.keywords.update(keywords)
12601264

testing/test_mark.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,3 +1130,42 @@ def test_addmarker_getmarker():
11301130
node.add_marker("b")
11311131
node.get_marker("a").combined
11321132
node.get_marker("b").combined
1133+
1134+
1135+
@pytest.mark.issue("https://github.com/pytest-dev/pytest/issues/3605")
1136+
@pytest.mark.filterwarnings("ignore")
1137+
def test_markers_from_parametrize(testdir):
1138+
testdir.makepyfile(
1139+
"""
1140+
from __future__ import print_function
1141+
import pytest
1142+
1143+
first_custom_mark = pytest.mark.custom_marker
1144+
custom_mark = pytest.mark.custom_mark
1145+
@pytest.fixture(autouse=True)
1146+
def trigger(request):
1147+
custom_mark =request.node.get_marker('custom_mark')
1148+
print("Custom mark %s" % custom_mark)
1149+
1150+
@custom_mark("custom mark non parametrized")
1151+
def test_custom_mark_non_parametrized():
1152+
print("Hey from test")
1153+
1154+
@pytest.mark.parametrize(
1155+
"obj_type",
1156+
[
1157+
first_custom_mark("first custom mark")("template"),
1158+
pytest.param( # Think this should be recommended way?
1159+
"disk",
1160+
marks=custom_mark('custom mark1')
1161+
),
1162+
custom_mark("custom mark2")("vm"), # Tried also this
1163+
]
1164+
)
1165+
def test_custom_mark_parametrized(obj_type):
1166+
print("obj_type is:", obj_type)
1167+
"""
1168+
)
1169+
1170+
result = testdir.runpytest()
1171+
result.assert_outcomes(passed=4)

0 commit comments

Comments
 (0)