Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two minor tweaks in MarkDecorator's implementation #6150

Merged
merged 2 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions src/_pytest/mark/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import warnings
from collections import namedtuple
from collections.abc import MutableMapping
from operator import attrgetter
from typing import Set

import attr
Expand All @@ -17,16 +16,6 @@
EMPTY_PARAMETERSET_OPTION = "empty_parameter_set_mark"


def alias(name, warning=None):
getter = attrgetter(name)

def warned(self):
warnings.warn(warning, stacklevel=2)
return getter(self)

return property(getter if warning is None else warned, doc="alias for " + name)


def istestfunc(func):
return (
hasattr(func, "__call__")
Expand Down Expand Up @@ -205,17 +194,25 @@ def test_function():

mark = attr.ib(validator=attr.validators.instance_of(Mark))

name = alias("mark.name")
args = alias("mark.args")
kwargs = alias("mark.kwargs")
@property
def name(self):
"""alias for mark.name"""
return self.mark.name

@property
def args(self):
"""alias for mark.args"""
return self.mark.args
bluetech marked this conversation as resolved.
Show resolved Hide resolved

@property
def kwargs(self):
"""alias for mark.kwargs"""
return self.mark.kwargs

@property
def markname(self):
return self.name # for backward-compat (2.4.1 had this attr)

def __eq__(self, other):
return self.mark == other.mark if isinstance(other, MarkDecorator) else False

def __repr__(self):
return "<MarkDecorator {!r}>".format(self.mark)

Expand Down
6 changes: 6 additions & 0 deletions testing/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,12 @@ class TestMarkDecorator:
def test__eq__(self, lhs, rhs, expected):
assert (lhs == rhs) == expected

def test_aliases(self) -> None:
md = pytest.mark.foo(1, "2", three=3)
assert md.name == "foo"
assert md.args == (1, "2")
assert md.kwargs == {"three": 3}


@pytest.mark.parametrize("mark", [None, "", "skip", "xfail"])
def test_parameterset_for_parametrize_marks(testdir, mark):
Expand Down