Skip to content

Commit 934ca13

Browse files
fix #3631 - don't store legacy markinfo when its impossible
1 parent 8680dfc commit 934ca13

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

changelog/3631.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No longer raise AttributeError when legacy marks can't be stored.

src/_pytest/mark/structures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def store_legacy_markinfo(func, mark):
259259
if holder is None:
260260
holder = MarkInfo.for_mark(mark)
261261
setattr(func, mark.name, holder)
262-
else:
262+
elif isinstance(holder, MarkInfo):
263263
holder.add_mark(mark)
264264

265265

testing/test_mark.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ def f():
6363
mark.hello(f)
6464
assert f.hello
6565

66+
def test_mark_legacy_ignore_fail(self):
67+
def add_attribute(func):
68+
func.foo = 1
69+
return func
70+
71+
@pytest.mark.foo
72+
@add_attribute
73+
def test_fun():
74+
pass
75+
76+
assert test_fun.foo == 1
77+
assert test_fun.pytestmark
78+
6679
@ignore_markinfo
6780
def test_pytest_mark_keywords(self):
6881
mark = Mark()

0 commit comments

Comments
 (0)