fix unittest emulation: TestCase.runTest is now ignored
if there are test* methods.
This commit is contained in:
parent
05c86aeb28
commit
aa79c0a4b9
|
@ -7,6 +7,9 @@ Changes between 2.3.1 and 2.3.2.dev
|
||||||
|
|
||||||
- fix teardown-ordering for parametrized setups
|
- 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
|
- "python setup.py test" now works with pytest itself
|
||||||
|
|
||||||
- fix/improve internal/packaging related bits:
|
- fix/improve internal/packaging related bits:
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
#
|
#
|
||||||
__version__ = '2.3.2.dev7'
|
__version__ = '2.3.2.dev8'
|
||||||
|
|
|
@ -28,6 +28,7 @@ class UnitTestCase(pytest.Class):
|
||||||
loader = py.std.unittest.TestLoader()
|
loader = py.std.unittest.TestLoader()
|
||||||
module = self.getparent(pytest.Module).obj
|
module = self.getparent(pytest.Module).obj
|
||||||
cls = self.obj
|
cls = self.obj
|
||||||
|
foundsomething = False
|
||||||
for name in loader.getTestCaseNames(self.obj):
|
for name in loader.getTestCaseNames(self.obj):
|
||||||
x = getattr(self.obj, name)
|
x = getattr(self.obj, name)
|
||||||
funcobj = getattr(x, 'im_func', x)
|
funcobj = getattr(x, 'im_func', x)
|
||||||
|
@ -35,7 +36,9 @@ class UnitTestCase(pytest.Class):
|
||||||
if hasattr(funcobj, 'todo'):
|
if hasattr(funcobj, 'todo'):
|
||||||
pytest.mark.xfail(reason=str(funcobj.todo))(funcobj)
|
pytest.mark.xfail(reason=str(funcobj.todo))(funcobj)
|
||||||
yield TestCaseFunction(name, parent=self)
|
yield TestCaseFunction(name, parent=self)
|
||||||
|
foundsomething = True
|
||||||
|
|
||||||
|
if not foundsomething:
|
||||||
if getattr(self.obj, 'runTest', None) is not None:
|
if getattr(self.obj, 'runTest', None) is not None:
|
||||||
yield TestCaseFunction('runTest', parent=self)
|
yield TestCaseFunction('runTest', parent=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.3.2.dev7',
|
version='2.3.2.dev8',
|
||||||
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'],
|
||||||
|
|
|
@ -18,12 +18,21 @@ def test_runTest_method(testdir):
|
||||||
testpath=testdir.makepyfile("""
|
testpath=testdir.makepyfile("""
|
||||||
import unittest
|
import unittest
|
||||||
pytest_plugins = "pytest_unittest"
|
pytest_plugins = "pytest_unittest"
|
||||||
class MyTestCase(unittest.TestCase):
|
class MyTestCaseWithRunTest(unittest.TestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
self.assertEquals('foo', 'foo')
|
self.assertEquals('foo', 'foo')
|
||||||
|
class MyTestCaseWithoutRunTest(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
self.assertEquals('foo', 'foo')
|
||||||
|
def test_something(self):
|
||||||
|
pass
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest("-v")
|
||||||
|
result.stdout.fnmatch_lines("""
|
||||||
|
*MyTestCaseWithRunTest.runTest*
|
||||||
|
*MyTestCaseWithoutRunTest.test_something*
|
||||||
|
*2 passed*
|
||||||
""")
|
""")
|
||||||
reprec = testdir.inline_run(testpath)
|
|
||||||
assert reprec.matchreport('runTest').passed
|
|
||||||
|
|
||||||
def test_isclasscheck_issue53(testdir):
|
def test_isclasscheck_issue53(testdir):
|
||||||
testpath = testdir.makepyfile("""
|
testpath = testdir.makepyfile("""
|
||||||
|
|
Loading…
Reference in New Issue