fix: mark.* objects are now immutable as long as they are not an attribute on a function, enables usage like this::

xfail = pytest.mark.xfail

    @xfail
    def test_func1():
        pass

    @xfail(reason="123")
    def test_func2():
        pass

where previously test_func1 and test_func2 would wrongly share the same reason
because the xfail object was modified in place.
This commit is contained in:
holger krekel
2010-11-20 20:17:38 +01:00
parent 9a21a81740
commit bd5a9ba392
3 changed files with 25 additions and 10 deletions

View File

@@ -101,10 +101,10 @@ class MarkDecorator:
def test_function():
pass
"""
def __init__(self, name):
def __init__(self, name, args=None, kwargs=None):
self.markname = name
self.kwargs = {}
self.args = []
self.args = args or ()
self.kwargs = kwargs or {}
def __repr__(self):
d = self.__dict__.copy()
@@ -134,12 +134,12 @@ class MarkDecorator:
setattr(func, self.markname, holder)
else:
holder.kwargs.update(self.kwargs)
holder.args.extend(self.args)
holder.args += self.args
return func
else:
self.args.extend(args)
self.kwargs.update(kwargs)
return self
kw = self.kwargs.copy()
kw.update(kwargs)
args = self.args + args
return self.__class__(self.markname, args=args, kwargs=kw)
class MarkInfo:
""" Marking object created by :class:`MarkDecorator` instances. """