Skip to content

Commit 7b47dfb

Browse files
authored
Merge pull request #3634 from RonnyPfannschmidt/merge-from-master
Merge from master
2 parents e9371a5 + 3c73d62 commit 7b47dfb

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
@@ -1139,3 +1139,42 @@ def test_addmarker_order():
11391139
node.add_marker("c", append=False)
11401140
extracted = [x.name for x in node.iter_markers()]
11411141
assert extracted == ["c", "a", "b"]
1142+
1143+
1144+
@pytest.mark.issue("https://github.com/pytest-dev/pytest/issues/3605")
1145+
@pytest.mark.filterwarnings("ignore")
1146+
def test_markers_from_parametrize(testdir):
1147+
testdir.makepyfile(
1148+
"""
1149+
from __future__ import print_function
1150+
import pytest
1151+
1152+
first_custom_mark = pytest.mark.custom_marker
1153+
custom_mark = pytest.mark.custom_mark
1154+
@pytest.fixture(autouse=True)
1155+
def trigger(request):
1156+
custom_mark =request.node.get_marker('custom_mark')
1157+
print("Custom mark %s" % custom_mark)
1158+
1159+
@custom_mark("custom mark non parametrized")
1160+
def test_custom_mark_non_parametrized():
1161+
print("Hey from test")
1162+
1163+
@pytest.mark.parametrize(
1164+
"obj_type",
1165+
[
1166+
first_custom_mark("first custom mark")("template"),
1167+
pytest.param( # Think this should be recommended way?
1168+
"disk",
1169+
marks=custom_mark('custom mark1')
1170+
),
1171+
custom_mark("custom mark2")("vm"), # Tried also this
1172+
]
1173+
)
1174+
def test_custom_mark_parametrized(obj_type):
1175+
print("obj_type is:", obj_type)
1176+
"""
1177+
)
1178+
1179+
result = testdir.runpytest()
1180+
result.assert_outcomes(passed=4)

0 commit comments

Comments
 (0)