[TIP] Nose teardown functions not run while expected to
Raphael Marvie
raphael.marvie at univ-lille1.fr
Sat Mar 9 09:01:05 PST 2013
Dear TIP list,
I am trying to use nose for my tests on a new project. In addition to
finding and running the tests with nosetests, I am attempting to use
nose API for writing the tests.
However, I am facing a problem with the execution of the teardown for
failing tests. When a single test fail all the test suite fail as the
teardown of the test has not been run, so my test database is not in a
coherent state. Here is the simplest code I can write that illustrate my
problem:
import nose
def setup_func():
print 'setup test'
def teardown_func():
print 'teardown test'
@nose.with_setup(setup_func, teardown_func)
def test_i_should_fail():
nose.tools.assert_true(False)
Running this test displays the failing assertion as well as the 'setup
test' printing, but 'teadown test' is not printed. I was expecting my
test to fail but to run the teardown_func anyway.
In my test suite, the setup creates objects in the test database and the
teardown removes these objects, so each test uses a clean db. On success
every thing is fine, when a single test fail all the following ones also
fail as the database is not clean and some uniqueness db constraints are
violated.
Am I improperly using nose configuration or use ?
Thanks for any hint,
r.
--
Raphael Marvie
LIFL - Université Lille 1
+33 3 20 33 59 51
More information about the testing-in-python
mailing list