From 84b2c81db4b998e41bc0d2583e4acbc47544e103 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 8 Nov 2019 00:55:23 +0200 Subject: [PATCH] Drop the "alias" helper used in MarkDecorator It is a little too obscure IMO, but the reason I want to drop it is that type checking has no hope of understanding such dynamic constructs. The warning argument wasn't used. --- src/_pytest/mark/structures.py | 28 ++++++++++++++-------------- testing/test_mark.py | 6 ++++++ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index 924d980f3..18ebc506a 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -2,7 +2,6 @@ import inspect import warnings from collections import namedtuple from collections.abc import MutableMapping -from operator import attrgetter from typing import Set import attr @@ -17,16 +16,6 @@ from _pytest.warning_types import PytestUnknownMarkWarning 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__") @@ -205,9 +194,20 @@ class MarkDecorator: 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 + + @property + def kwargs(self): + """alias for mark.kwargs""" + return self.mark.kwargs @property def markname(self): diff --git a/testing/test_mark.py b/testing/test_mark.py index 2c12c0451..071775aef 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -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):