Apply suggestions from code review

Co-authored-by: Ran Benita <ran@unusedvar.com>
This commit is contained in:
Ronny Pfannschmidt 2022-10-12 10:20:16 +02:00 committed by GitHub
parent c42bb36009
commit f13f4360d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -1 +1,5 @@
Consider the full mro when getting marks from classes.
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.
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.
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.

View File

@ -357,9 +357,15 @@ class MarkDecorator:
def get_unpacked_marks(
obj: Union[object, type],
*,
consider_mro: bool = True,
) -> List[Mark]:
"""Obtain the unpacked marks that are stored on an object."""
"""Obtain the unpacked marks that are stored on an object.
If obj is a class and consider_mro is true, return marks applied to
this class and all of its super-classes in MRO order. If consider_mro
is false, only return marks applied directly to this class.
"""
if isinstance(obj, type):
if not consider_mro:
mark_lists = [obj.__dict__.get("pytestmark", [])]

View File

@ -1111,7 +1111,7 @@ def test_marker_expr_eval_failure_handling(pytester: Pytester, expr) -> None:
assert result.ret == ExitCode.USAGE_ERROR
def test_mark_mro():
def test_mark_mro() -> None:
xfail = pytest.mark.xfail
@xfail("a")