How to execute setup and teardown functions once for all nosetests tests?
def common_setup():
#time consuming code
pass
def common_teardown():
#tidy up
pass
def test_1():
pass
def test_2():
pass
#desired behavior
common_setup()
test_1()
test_2()
common_teardown()
Note that there exists a similar question with an answer that is not working with python 2.7.9-1, python-unittest2 0.5.1-1 and python-nose 1.3.6-1 after replacing the dots with pass
and adding the line import unittest
.
Unfortunately my reputation is too low to comment on that.
You can have a module level setup function. According to nose documentation:
So, more specifically, for your case:
Running test gives you:
It does not matter which name you choose, so both
setup
andsetup_module
would work the same, butsetup_module
has more clarity to it.