From f28b834426890bee7b7962b6a920f45108a9ce10 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 18 Jan 2019 22:05:41 +0100 Subject: [PATCH] fix #4649 - also transfer markers to keywordmapping as it turns out it is distinct from nodekeywords and behaves completely different --- changelog/4649.bugfix.rst | 1 + src/_pytest/mark/legacy.py | 9 +++++---- .../marks/marks_considered_keywords/conftest.py | 0 .../marks_considered_keywords/test_marks_as_keywords.py | 6 ++++++ testing/test_mark.py | 7 +++++++ 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 changelog/4649.bugfix.rst create mode 100644 testing/example_scripts/marks/marks_considered_keywords/conftest.py create mode 100644 testing/example_scripts/marks/marks_considered_keywords/test_marks_as_keywords.py 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", [