diff --git a/changelog/4649.bugfix.rst b/changelog/4649.bugfix.rst new file mode 100644 index 000000000..74b241781 --- /dev/null +++ b/changelog/4649.bugfix.rst @@ -0,0 +1 @@ +Restore marks being considered keywords for keyword expressions. diff --git a/src/_pytest/mark/legacy.py b/src/_pytest/mark/legacy.py index cea136bff..f784ffa20 100644 --- a/src/_pytest/mark/legacy.py +++ b/src/_pytest/mark/legacy.py @@ -45,13 +45,14 @@ class KeywordMapping(object): mapped_names.add(item.name) # Add the names added as extra keywords to current or parent items - for name in item.listextrakeywords(): - mapped_names.add(name) + mapped_names.update(item.listextrakeywords()) # Add the names attached to the current function through direct assignment if hasattr(item, "function"): - for name in item.function.__dict__: - mapped_names.add(name) + mapped_names.update(item.function.__dict__) + + # add the markers to the keywords as we no longer handle them correctly + mapped_names.update(mark.name for mark in item.iter_markers()) return cls(mapped_names) diff --git a/testing/example_scripts/marks/marks_considered_keywords/conftest.py b/testing/example_scripts/marks/marks_considered_keywords/conftest.py new file mode 100644 index 000000000..e69de29bb diff --git a/testing/example_scripts/marks/marks_considered_keywords/test_marks_as_keywords.py b/testing/example_scripts/marks/marks_considered_keywords/test_marks_as_keywords.py new file mode 100644 index 000000000..35a2c7b76 --- /dev/null +++ b/testing/example_scripts/marks/marks_considered_keywords/test_marks_as_keywords.py @@ -0,0 +1,6 @@ +import pytest + + +@pytest.mark.foo +def test_mark(): + pass diff --git a/testing/test_mark.py b/testing/test_mark.py index a10e2e19d..f7d8cf689 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -292,6 +292,13 @@ def test_keyword_option_custom(spec, testdir): assert list(passed) == list(passed_result) +def test_keyword_option_considers_mark(testdir): + testdir.copy_example("marks/marks_considered_keywords") + rec = testdir.inline_run("-k", "foo") + passed = rec.listoutcomes()[0] + assert len(passed) == 1 + + @pytest.mark.parametrize( "spec", [