Skip to content

Commit f13f436

Browse files
Apply suggestions from code review
Co-authored-by: Ran Benita <[email protected]>
1 parent c42bb36 commit f13f436

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

changelog/7792.bugfix.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
Consider the full mro when getting marks from classes.
1+
Marks are now inherited according to the full MRO in test classes. Previously, if a test class inherited from two or more classes, only marks from the first super-class would apply.
2+
3+
When inheriting marks from super-classes, marks from the sub-classes are now ordered before marks from the super-classes, in MRO order. Previously it was the reverse.
4+
5+
When inheriting marks from super-classes, the `pytestmark` attribute of the sub-class now only contains the marks directly applied to it. Previously, it also contained marks from its super-classes. Please note that this attribute should not normally be accessed directly; use :func:`pytest.Node.iter_markers` instead.

src/_pytest/mark/structures.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,15 @@ def __call__(self, *args: object, **kwargs: object):
357357

358358
def get_unpacked_marks(
359359
obj: Union[object, type],
360+
*,
360361
consider_mro: bool = True,
361362
) -> List[Mark]:
362-
"""Obtain the unpacked marks that are stored on an object."""
363+
"""Obtain the unpacked marks that are stored on an object.
364+
365+
If obj is a class and consider_mro is true, return marks applied to
366+
this class and all of its super-classes in MRO order. If consider_mro
367+
is false, only return marks applied directly to this class.
368+
"""
363369
if isinstance(obj, type):
364370
if not consider_mro:
365371
mark_lists = [obj.__dict__.get("pytestmark", [])]

testing/test_mark.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ def test_foo():
11111111
assert result.ret == ExitCode.USAGE_ERROR
11121112

11131113

1114-
def test_mark_mro():
1114+
def test_mark_mro() -> None:
11151115
xfail = pytest.mark.xfail
11161116

11171117
@xfail("a")

0 commit comments

Comments
 (0)