Skip to content

Commit

Permalink
add tests for mark extraction and fix rep of markdecorator
Browse files Browse the repository at this point in the history
  • Loading branch information
RonnyPfannschmidt committed Mar 17, 2017
1 parent 9803119 commit 63ac40b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 5 additions & 1 deletion _pytest/mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def istestfunc(func):
return hasattr(func, "__call__") and \
getattr(func, "__name__", "<lambda>") != "<lambda>"


class MarkDecorator(object):
""" A decorator for test functions and test classes. When applied
it will create :class:`MarkInfo` objects which may be
Expand Down Expand Up @@ -309,8 +310,11 @@ def __init__(self, mark):
def markname(self):
return self.name # for backward-compat (2.4.1 had this attr)

def __eq__(self, other):
return self.mark == other.mark

def __repr__(self):
return "<MarkDecorator %r>" % self.mark
return "<MarkDecorator %r>" % (self.mark,)

def __call__(self, *args, **kwargs):
""" if passed a single callable argument: decorate it with mark info.
Expand Down
15 changes: 14 additions & 1 deletion testing/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

import pytest
from _pytest.mark import MarkGenerator as Mark
from _pytest.mark import MarkGenerator as Mark, ParameterSet

class TestMark(object):
def test_markinfo_repr(self):
Expand Down Expand Up @@ -742,3 +742,16 @@ def assert_test_is_not_selected(keyword):

assert_test_is_not_selected("__")
assert_test_is_not_selected("()")


@pytest.mark.parametrize('argval, expected', [
(pytest.mark.skip()((1, 2)),
ParameterSet(values=(1, 2), marks=[pytest.mark.skip], id=None)),
(pytest.mark.xfail(pytest.mark.skip()((1, 2))),
ParameterSet(values=(1, 2),
marks=[pytest.mark.xfail, pytest.mark.skip], id=None)),
])
def test_parameterset_extractfrom(argval, expected):
extracted = ParameterSet.extract_from(argval)
assert extracted == expected

0 comments on commit 63ac40b

Please sign in to comment.