Skip to content

Commit

Permalink
Reverse order on marks from MRO
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jul 1, 2023
1 parent b77d0de commit 43fd1fe
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/10447.bugfix.rst
@@ -0,0 +1 @@
When resolving marks from a class hierarchy MRO, reverse the order so that more basic classes' marks will be processed ahead of ancestral classes.
4 changes: 3 additions & 1 deletion src/_pytest/mark/structures.py
Expand Up @@ -374,7 +374,9 @@ def get_unpacked_marks(
if not consider_mro:
mark_lists = [obj.__dict__.get("pytestmark", [])]
else:
mark_lists = [x.__dict__.get("pytestmark", []) for x in obj.__mro__]
mark_lists = reversed(
[x.__dict__.get("pytestmark", []) for x in obj.__mro__]
)
mark_list = []
for item in mark_lists:
if isinstance(item, list):
Expand Down
2 changes: 1 addition & 1 deletion testing/test_mark.py
Expand Up @@ -1130,6 +1130,6 @@ class C(A, B):

all_marks = get_unpacked_marks(C)

assert all_marks == [xfail("c").mark, xfail("a").mark, xfail("b").mark]
assert all_marks == [xfail("b").mark, xfail("a").mark, xfail("c").mark]

assert get_unpacked_marks(C, consider_mro=False) == [xfail("c").mark]

0 comments on commit 43fd1fe

Please sign in to comment.