From 5bd5b8c68aed33ad6b74f79208ef012e0b16c232 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Fri, 29 Jun 2018 11:35:43 +0200 Subject: [PATCH] fix #3631 - don't store legacy markinfo when its impossible --- changelog/3631.bugfix.rst | 1 + src/_pytest/mark/structures.py | 2 +- testing/test_mark.py | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 changelog/3631.bugfix.rst 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()