fix unittest/marker integration
This commit is contained in:
parent
e3a8b1e062
commit
c126cac98d
|
@ -1,2 +1,2 @@
|
||||||
#
|
#
|
||||||
__version__ = '2.2.2.dev4'
|
__version__ = '2.2.2.dev5'
|
||||||
|
|
|
@ -221,9 +221,9 @@ class PyCollectorMixin(PyobjMixin, pytest.Collector):
|
||||||
module = self.getparent(Module).obj
|
module = self.getparent(Module).obj
|
||||||
clscol = self.getparent(Class)
|
clscol = self.getparent(Class)
|
||||||
cls = clscol and clscol.obj or None
|
cls = clscol and clscol.obj or None
|
||||||
|
transfer_markers(funcobj, cls, module)
|
||||||
metafunc = Metafunc(funcobj, config=self.config,
|
metafunc = Metafunc(funcobj, config=self.config,
|
||||||
cls=cls, module=module)
|
cls=cls, module=module)
|
||||||
transfer_markers(metafunc)
|
|
||||||
gentesthook = self.config.hook.pytest_generate_tests
|
gentesthook = self.config.hook.pytest_generate_tests
|
||||||
extra = [module]
|
extra = [module]
|
||||||
if cls is not None:
|
if cls is not None:
|
||||||
|
@ -241,20 +241,19 @@ class PyCollectorMixin(PyobjMixin, pytest.Collector):
|
||||||
l.append(function)
|
l.append(function)
|
||||||
return l
|
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
|
# XXX this should rather be code in the mark plugin or the mark
|
||||||
# plugin should merge with the python plugin.
|
# plugin should merge with the python plugin.
|
||||||
for holder in (metafunc.cls, metafunc.module):
|
for holder in (cls, mod):
|
||||||
try:
|
try:
|
||||||
pytestmark = holder.pytestmark
|
pytestmark = holder.pytestmark
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
continue
|
continue
|
||||||
if isinstance(pytestmark, list):
|
if isinstance(pytestmark, list):
|
||||||
for mark in pytestmark:
|
for mark in pytestmark:
|
||||||
mark(metafunc.function)
|
mark(funcobj)
|
||||||
else:
|
else:
|
||||||
pytestmark(metafunc.function)
|
pytestmark(funcobj)
|
||||||
|
|
||||||
|
|
||||||
class Module(pytest.File, PyCollectorMixin):
|
class Module(pytest.File, PyCollectorMixin):
|
||||||
def _getobj(self):
|
def _getobj(self):
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
import pytest, py
|
import pytest, py
|
||||||
import sys, pdb
|
import sys, pdb
|
||||||
|
|
||||||
|
# for transfering markers
|
||||||
|
from _pytest.python import transfer_markers
|
||||||
|
|
||||||
def pytest_pycollect_makeitem(collector, name, obj):
|
def pytest_pycollect_makeitem(collector, name, obj):
|
||||||
unittest = sys.modules.get('unittest')
|
unittest = sys.modules.get('unittest')
|
||||||
if unittest is None:
|
if unittest is None:
|
||||||
|
@ -19,7 +22,12 @@ def pytest_pycollect_makeitem(collector, name, obj):
|
||||||
class UnitTestCase(pytest.Class):
|
class UnitTestCase(pytest.Class):
|
||||||
def collect(self):
|
def collect(self):
|
||||||
loader = py.std.unittest.TestLoader()
|
loader = py.std.unittest.TestLoader()
|
||||||
|
module = self.getparent(pytest.Module).obj
|
||||||
|
cls = self.obj
|
||||||
for name in loader.getTestCaseNames(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)
|
yield TestCaseFunction(name, parent=self)
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -24,7 +24,7 @@ def main():
|
||||||
name='pytest',
|
name='pytest',
|
||||||
description='py.test: simple powerful testing with Python',
|
description='py.test: simple powerful testing with Python',
|
||||||
long_description = long_description,
|
long_description = long_description,
|
||||||
version='2.2.2.dev4',
|
version='2.2.2.dev5',
|
||||||
url='http://pytest.org',
|
url='http://pytest.org',
|
||||||
license='MIT license',
|
license='MIT license',
|
||||||
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
||||||
|
|
Loading…
Reference in New Issue