fix unittest emulation: TestCase.runTest is now ignored

if there are test* methods.
This commit is contained in:
holger krekel 2012-10-22 16:25:09 +02:00
parent 05c86aeb28
commit aa79c0a4b9
5 changed files with 22 additions and 7 deletions

View File

@ -7,6 +7,9 @@ Changes between 2.3.1 and 2.3.2.dev
- fix teardown-ordering for parametrized setups
- fix unittest behaviour: TestCase.runtest only called if there are
test methods defined
- "python setup.py test" now works with pytest itself
- fix/improve internal/packaging related bits:

View File

@ -1,2 +1,2 @@
#
__version__ = '2.3.2.dev7'
__version__ = '2.3.2.dev8'

View File

@ -28,6 +28,7 @@ class UnitTestCase(pytest.Class):
loader = py.std.unittest.TestLoader()
module = self.getparent(pytest.Module).obj
cls = self.obj
foundsomething = False
for name in loader.getTestCaseNames(self.obj):
x = getattr(self.obj, name)
funcobj = getattr(x, 'im_func', x)
@ -35,9 +36,11 @@ class UnitTestCase(pytest.Class):
if hasattr(funcobj, 'todo'):
pytest.mark.xfail(reason=str(funcobj.todo))(funcobj)
yield TestCaseFunction(name, parent=self)
foundsomething = True
if getattr(self.obj, 'runTest', None) is not None:
yield TestCaseFunction('runTest', parent=self)
if not foundsomething:
if getattr(self.obj, 'runTest', None) is not None:
yield TestCaseFunction('runTest', parent=self)
def setup(self):
meth = getattr(self.obj, 'setUpClass', None)

View File

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

View File

@ -18,12 +18,21 @@ def test_runTest_method(testdir):
testpath=testdir.makepyfile("""
import unittest
pytest_plugins = "pytest_unittest"
class MyTestCase(unittest.TestCase):
class MyTestCaseWithRunTest(unittest.TestCase):
def runTest(self):
self.assertEquals('foo', 'foo')
class MyTestCaseWithoutRunTest(unittest.TestCase):
def runTest(self):
self.assertEquals('foo', 'foo')
def test_something(self):
pass
""")
reprec = testdir.inline_run(testpath)
assert reprec.matchreport('runTest').passed
result = testdir.runpytest("-v")
result.stdout.fnmatch_lines("""
*MyTestCaseWithRunTest.runTest*
*MyTestCaseWithoutRunTest.test_something*
*2 passed*
""")
def test_isclasscheck_issue53(testdir):
testpath = testdir.makepyfile("""