allow setup_class in unittest test cases
This commit is contained in:
parent
6ebd5f2900
commit
840eed28be
|
@ -26,11 +26,13 @@ class UnitTestCase(pytest.Class):
|
||||||
meth = getattr(self.obj, 'setUpClass', None)
|
meth = getattr(self.obj, 'setUpClass', None)
|
||||||
if meth is not None:
|
if meth is not None:
|
||||||
meth()
|
meth()
|
||||||
|
super(UnitTestCase, self).setup()
|
||||||
|
|
||||||
def teardown(self):
|
def teardown(self):
|
||||||
meth = getattr(self.obj, 'tearDownClass', None)
|
meth = getattr(self.obj, 'tearDownClass', None)
|
||||||
if meth is not None:
|
if meth is not None:
|
||||||
meth()
|
meth()
|
||||||
|
super(UnitTestCase, self).teardown()
|
||||||
|
|
||||||
class TestCaseFunction(pytest.Function):
|
class TestCaseFunction(pytest.Function):
|
||||||
_excinfo = None
|
_excinfo = None
|
||||||
|
|
|
@ -5,7 +5,7 @@ see http://pytest.org for documentation and details
|
||||||
|
|
||||||
(c) Holger Krekel and others, 2004-2010
|
(c) Holger Krekel and others, 2004-2010
|
||||||
"""
|
"""
|
||||||
__version__ = '2.0.0.dev35'
|
__version__ = '2.0.0.dev36'
|
||||||
__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.0.dev35',
|
version='2.0.0.dev36',
|
||||||
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'],
|
||||||
|
|
|
@ -82,7 +82,7 @@ def test_module_level_pytestmark(testdir):
|
||||||
reprec = testdir.inline_run(testpath, "-s")
|
reprec = testdir.inline_run(testpath, "-s")
|
||||||
reprec.assertoutcome(skipped=1)
|
reprec.assertoutcome(skipped=1)
|
||||||
|
|
||||||
def test_class_setup(testdir):
|
def test_setup_setUpClass(testdir):
|
||||||
testpath = testdir.makepyfile("""
|
testpath = testdir.makepyfile("""
|
||||||
import unittest
|
import unittest
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -104,6 +104,26 @@ def test_class_setup(testdir):
|
||||||
reprec = testdir.inline_run(testpath)
|
reprec = testdir.inline_run(testpath)
|
||||||
reprec.assertoutcome(passed=3)
|
reprec.assertoutcome(passed=3)
|
||||||
|
|
||||||
|
def test_setup_class(testdir):
|
||||||
|
testpath = testdir.makepyfile("""
|
||||||
|
import unittest
|
||||||
|
import pytest
|
||||||
|
class MyTestCase(unittest.TestCase):
|
||||||
|
x = 0
|
||||||
|
def setup_class(cls):
|
||||||
|
cls.x += 1
|
||||||
|
def test_func1(self):
|
||||||
|
assert self.x == 1
|
||||||
|
def test_func2(self):
|
||||||
|
assert self.x == 1
|
||||||
|
def teardown_class(cls):
|
||||||
|
cls.x -= 1
|
||||||
|
def test_teareddown():
|
||||||
|
assert MyTestCase.x == 0
|
||||||
|
""")
|
||||||
|
reprec = testdir.inline_run(testpath)
|
||||||
|
reprec.assertoutcome(passed=3)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.multi(type=['Error', 'Failure'])
|
@pytest.mark.multi(type=['Error', 'Failure'])
|
||||||
def test_testcase_adderrorandfailure_defers(testdir, type):
|
def test_testcase_adderrorandfailure_defers(testdir, type):
|
||||||
|
|
Loading…
Reference in New Issue