fix issue89 - allow py.test.mark decorators to be used with classes

(if you are using >=python2.6)
also allow to have multiple markers applied at class level
and test and fix a bug with chained skip/xfail decorators:
if any of the conditions is true a test will be skipped/xfailed
with a explanation which condition evaluated to true.

--HG--
branch : trunk
This commit is contained in:
holger krekel
2010-05-21 18:11:47 +02:00
parent 67ec87e7f9
commit 4f7ef0b63f
7 changed files with 192 additions and 54 deletions

View File

@@ -68,11 +68,41 @@ class TestFunctional:
keywords = item.readkeywords()
assert 'hello' in keywords
def test_mark_per_class(self, testdir):
def test_marklist_per_class(self, testdir):
modcol = testdir.getmodulecol("""
import py
class TestClass:
pytestmark = py.test.mark.hello
pytestmark = [py.test.mark.hello, py.test.mark.world]
def test_func(self):
assert TestClass.test_func.hello
assert TestClass.test_func.world
""")
clscol = modcol.collect()[0]
item = clscol.collect()[0].collect()[0]
keywords = item.readkeywords()
assert 'hello' in keywords
def test_marklist_per_module(self, testdir):
modcol = testdir.getmodulecol("""
import py
pytestmark = [py.test.mark.hello, py.test.mark.world]
class TestClass:
def test_func(self):
assert TestClass.test_func.hello
assert TestClass.test_func.world
""")
clscol = modcol.collect()[0]
item = clscol.collect()[0].collect()[0]
keywords = item.readkeywords()
assert 'hello' in keywords
assert 'world' in keywords
@py.test.mark.skipif("sys.version_info < (2,6)")
def test_mark_per_class_decorator(self, testdir):
modcol = testdir.getmodulecol("""
import py
@py.test.mark.hello
class TestClass:
def test_func(self):
assert TestClass.test_func.hello
""")
@@ -81,6 +111,23 @@ class TestFunctional:
keywords = item.readkeywords()
assert 'hello' in keywords
@py.test.mark.skipif("sys.version_info < (2,6)")
def test_mark_per_class_decorator_plus_existing_dec(self, testdir):
modcol = testdir.getmodulecol("""
import py
@py.test.mark.hello
class TestClass:
pytestmark = py.test.mark.world
def test_func(self):
assert TestClass.test_func.hello
assert TestClass.test_func.world
""")
clscol = modcol.collect()[0]
item = clscol.collect()[0].collect()[0]
keywords = item.readkeywords()
assert 'hello' in keywords
assert 'world' in keywords
def test_merging_markers(self, testdir):
p = testdir.makepyfile("""
import py

View File

@@ -52,6 +52,39 @@ class TestEvaluator:
assert expl == "hello world"
assert ev.get("attr") == 2
def test_marked_one_arg_twice(self, testdir):
lines = [
'''@py.test.mark.skipif("not hasattr(os, 'murks')")''',
'''@py.test.mark.skipif("hasattr(os, 'murks')")'''
]
for i in range(0, 2):
item = testdir.getitem("""
import py
%s
%s
def test_func():
pass
""" % (lines[i], lines[(i+1) %2]))
ev = MarkEvaluator(item, 'skipif')
assert ev
assert ev.istrue()
expl = ev.getexplanation()
assert expl == "condition: not hasattr(os, 'murks')"
def test_marked_one_arg_twice2(self, testdir):
item = testdir.getitem("""
import py
@py.test.mark.skipif("hasattr(os, 'murks')")
@py.test.mark.skipif("not hasattr(os, 'murks')")
def test_func():
pass
""")
ev = MarkEvaluator(item, 'skipif')
assert ev
assert ev.istrue()
expl = ev.getexplanation()
assert expl == "condition: not hasattr(os, 'murks')"
def test_skipif_class(self, testdir):
item, = testdir.getitems("""
import py