fix unittest/marker integration

This commit is contained in:
holger krekel 2011-12-28 16:47:08 +00:00
parent e3a8b1e062
commit c126cac98d
4 changed files with 15 additions and 8 deletions

View File

@ -1,2 +1,2 @@
#
__version__ = '2.2.2.dev4'
__version__ = '2.2.2.dev5'

View File

@ -221,9 +221,9 @@ class PyCollectorMixin(PyobjMixin, pytest.Collector):
module = self.getparent(Module).obj
clscol = self.getparent(Class)
cls = clscol and clscol.obj or None
transfer_markers(funcobj, cls, module)
metafunc = Metafunc(funcobj, config=self.config,
cls=cls, module=module)
transfer_markers(metafunc)
gentesthook = self.config.hook.pytest_generate_tests
extra = [module]
if cls is not None:
@ -241,20 +241,19 @@ class PyCollectorMixin(PyobjMixin, pytest.Collector):
l.append(function)
return l
def transfer_markers(metafunc):
def transfer_markers(funcobj, cls, mod):
# XXX this should rather be code in the mark plugin or the mark
# plugin should merge with the python plugin.
for holder in (metafunc.cls, metafunc.module):
for holder in (cls, mod):
try:
pytestmark = holder.pytestmark
except AttributeError:
continue
if isinstance(pytestmark, list):
for mark in pytestmark:
mark(metafunc.function)
mark(funcobj)
else:
pytestmark(metafunc.function)
pytestmark(funcobj)
class Module(pytest.File, PyCollectorMixin):
def _getobj(self):

View File

@ -2,6 +2,9 @@
import pytest, py
import sys, pdb
# for transfering markers
from _pytest.python import transfer_markers
def pytest_pycollect_makeitem(collector, name, obj):
unittest = sys.modules.get('unittest')
if unittest is None:
@ -19,7 +22,12 @@ def pytest_pycollect_makeitem(collector, name, obj):
class UnitTestCase(pytest.Class):
def collect(self):
loader = py.std.unittest.TestLoader()
module = self.getparent(pytest.Module).obj
cls = self.obj
for name in loader.getTestCaseNames(self.obj):
x = getattr(self.obj, name)
funcobj = getattr(x, 'im_func', x)
transfer_markers(funcobj, cls, module)
yield TestCaseFunction(name, parent=self)
def setup(self):

View File

@ -24,7 +24,7 @@ def main():
name='pytest',
description='py.test: simple powerful testing with Python',
long_description = long_description,
version='2.2.2.dev4',
version='2.2.2.dev5',
url='http://pytest.org',
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],