Skip to content

Commit f28b834

Browse files
fix #4649 - also transfer markers to keywordmapping
as it turns out it is distinct from nodekeywords and behaves completely different
1 parent 6154a5a commit f28b834

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

changelog/4649.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Restore marks being considered keywords for keyword expressions.

src/_pytest/mark/legacy.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ def from_item(cls, item):
4545
mapped_names.add(item.name)
4646

4747
# Add the names added as extra keywords to current or parent items
48-
for name in item.listextrakeywords():
49-
mapped_names.add(name)
48+
mapped_names.update(item.listextrakeywords())
5049

5150
# Add the names attached to the current function through direct assignment
5251
if hasattr(item, "function"):
53-
for name in item.function.__dict__:
54-
mapped_names.add(name)
52+
mapped_names.update(item.function.__dict__)
53+
54+
# add the markers to the keywords as we no longer handle them correctly
55+
mapped_names.update(mark.name for mark in item.iter_markers())
5556

5657
return cls(mapped_names)
5758

testing/example_scripts/marks/marks_considered_keywords/conftest.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pytest
2+
3+
4+
@pytest.mark.foo
5+
def test_mark():
6+
pass

testing/test_mark.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@ def test_pass():
292292
assert list(passed) == list(passed_result)
293293

294294

295+
def test_keyword_option_considers_mark(testdir):
296+
testdir.copy_example("marks/marks_considered_keywords")
297+
rec = testdir.inline_run("-k", "foo")
298+
passed = rec.listoutcomes()[0]
299+
assert len(passed) == 1
300+
301+
295302
@pytest.mark.parametrize(
296303
"spec",
297304
[

0 commit comments

Comments
 (0)