You can write your setup function and apply it using the with_setup
decorator:
from nose.tools import with_setup
def my_setup():
...
@with_setup(my_setup)
def test_one():
...
@with_setup(my_setup)
def test_two():
...
If you want to use the same setup for several test-cases you can use a similar method.
First you create the setup function, then you apply it to all the TestCases with a decorator:
def my_setup(self):
#do the setup for the test-case
def apply_setup(setup_func):
def wrap(cls):
cls.setup = setup_func
return cls
return wrap
@apply_setup(my_setup)
class MyTestCaseOne(unittest.TestCase):
def test_one(self):
...
def test_two(self):
...
@apply_setup(my_setup)
class MyTestCaseTwo(unittest.TestCase):
def test_one(self):
...
Or another way could be to simply assign your setup:
class MyTestCaseOne(unittest.TestCase):
setup = my_setup