fix issue 28 - setup_method now works with pytest_generate_tests
This commit is contained in:
parent
f1b5dae1fb
commit
6f3b84da9f
|
@ -1,6 +1,8 @@
|
||||||
Changes between 2.0.1 and 2.0.2
|
Changes between 2.0.1 and 2.0.2
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
|
||||||
|
- fix issue28 - setup_method and pytest_generate_tests work together
|
||||||
|
|
||||||
- fix issue24 - pytest_assertrepr_compare produces an in-line
|
- fix issue24 - pytest_assertrepr_compare produces an in-line
|
||||||
exception on python3
|
exception on python3
|
||||||
|
|
||||||
|
|
|
@ -297,13 +297,8 @@ class Instance(PyCollectorMixin, pytest.Collector):
|
||||||
class FunctionMixin(PyobjMixin):
|
class FunctionMixin(PyobjMixin):
|
||||||
""" mixin for the code common to Function and Generator.
|
""" mixin for the code common to Function and Generator.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
""" perform setup for this test function. """
|
""" perform setup for this test function. """
|
||||||
if inspect.ismethod(self.obj):
|
|
||||||
name = 'setup_method'
|
|
||||||
else:
|
|
||||||
name = 'setup_function'
|
|
||||||
if hasattr(self, '_preservedparent'):
|
if hasattr(self, '_preservedparent'):
|
||||||
obj = self._preservedparent
|
obj = self._preservedparent
|
||||||
elif isinstance(self.parent, Instance):
|
elif isinstance(self.parent, Instance):
|
||||||
|
@ -311,6 +306,10 @@ class FunctionMixin(PyobjMixin):
|
||||||
self.obj = self._getobj()
|
self.obj = self._getobj()
|
||||||
else:
|
else:
|
||||||
obj = self.parent.obj
|
obj = self.parent.obj
|
||||||
|
if inspect.ismethod(self.obj):
|
||||||
|
name = 'setup_method'
|
||||||
|
else:
|
||||||
|
name = 'setup_function'
|
||||||
setup_func_or_method = getattr(obj, name, None)
|
setup_func_or_method = getattr(obj, name, None)
|
||||||
if setup_func_or_method is not None:
|
if setup_func_or_method is not None:
|
||||||
setup_func_or_method(self.obj)
|
setup_func_or_method(self.obj)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""
|
"""
|
||||||
unit and functional testing with Python.
|
unit and functional testing with Python.
|
||||||
"""
|
"""
|
||||||
__version__ = '2.0.2.dev0'
|
__version__ = '2.0.2.dev1'
|
||||||
__all__ = ['main']
|
__all__ = ['main']
|
||||||
|
|
||||||
from _pytest.core import main, UsageError, _preloadplugins
|
from _pytest.core import main, UsageError, _preloadplugins
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -22,7 +22,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.0.2.dev0',
|
version='2.0.2.dev1',
|
||||||
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'],
|
||||||
|
|
|
@ -1062,6 +1062,21 @@ class TestGenfuncFunctional:
|
||||||
"*2 pass*",
|
"*2 pass*",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def test_issue28_setup_method_in_generate_tests(self, testdir):
|
||||||
|
p = testdir.makepyfile("""
|
||||||
|
def pytest_generate_tests(metafunc):
|
||||||
|
metafunc.addcall({'arg1': 1})
|
||||||
|
|
||||||
|
class TestClass:
|
||||||
|
def test_method(self, arg1):
|
||||||
|
assert arg1 == self.val
|
||||||
|
def setup_method(self, func):
|
||||||
|
self.val = 1
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest(p)
|
||||||
|
result.stdout.fnmatch_lines([
|
||||||
|
"*1 pass*",
|
||||||
|
])
|
||||||
|
|
||||||
def test_conftest_funcargs_only_available_in_subdir(testdir):
|
def test_conftest_funcargs_only_available_in_subdir(testdir):
|
||||||
sub1 = testdir.mkpydir("sub1")
|
sub1 = testdir.mkpydir("sub1")
|
||||||
|
|
Loading…
Reference in New Issue