diff --git a/changelog/3631.bugfix.rst b/changelog/3631.bugfix.rst new file mode 100644 index 000000000..261c41ccd --- /dev/null +++ b/changelog/3631.bugfix.rst @@ -0,0 +1 @@ +No longer raise AttributeError when legacy marks can't be stored. diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index d416e422b..3fb15bbc2 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -259,7 +259,7 @@ def store_legacy_markinfo(func, mark): if holder is None: holder = MarkInfo.for_mark(mark) setattr(func, mark.name, holder) - else: + elif isinstance(holder, MarkInfo): holder.add_mark(mark) diff --git a/testing/test_mark.py b/testing/test_mark.py index f87a4eded..e3d28189c 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -63,6 +63,19 @@ class TestMark(object): mark.hello(f) assert f.hello + def test_mark_legacy_ignore_fail(self): + def add_attribute(func): + func.foo = 1 + return func + + @pytest.mark.foo + @add_attribute + def test_fun(): + pass + + assert test_fun.foo == 1 + assert test_fun.pytestmark + @ignore_markinfo def test_pytest_mark_keywords(self): mark = Mark()