I ran nosetests on the tests written for unittest from my unittest fixture post.
No surprises.
Nose supports unittest style fixtures:
- module: setUpModule()/tearDownModule()
- class: setUpClass()/tearDownClass()
- around methods: setUp()/tearDown()
- add cleanup functions: addCleanup() called from setUp() and from a test
- skipping tests dynamically: testSkip() called from setUp()
- error conditions: don’t run the test or the matching tearDown if setUp fails. This is true for module, class, and method fixtures.
Here’s the output. (error cases omitted).
> nosetests -q -s test_fixtures:TestFixtures
in module test_fixtures - setUpModule()
in class TestFixtures - setUpClass()
in test_1 - setUp()
in test_1 - test_1()
in test_1 - tearDown()
in test_2 - setUp()
in test_2 - test_2()
in test_2 - tearDown()
in class TestFixtures - tearDownClass()
in module test_fixtures - tearDownModule()
----------------------------------------------------------------------
Ran 2 tests in 0.071s
OK
> nosetests -q -s test_fixtures:TestAddCleanup
in module test_fixtures - setUpModule()
in class TestAddCleanup - setUpClass()
in test_1 - setUp()
in test_1 - test_1()
in test_1 - tearDown()
in test_1 - cleanup_b()
in test_1 - cleanup_a()
in test_2 - setUp()
in test_2 - test_1()
in test_2 - tearDown()
in test_2 - cleanup_a()
in class TestAddCleanup - tearDownClass()
in module test_fixtures - tearDownModule()
----------------------------------------------------------------------
Ran 2 tests in 0.079s
OK
> nosetests -q -s test_fixtures:TestSkip
in module test_fixtures - setUpModule()
in class TestSkip - setUpClass()
in test_1 - setUp()
in test_1 - test_1()
in test_1 - tearDown()
in test_2 - setUp()
in class TestSkip - tearDownClass()
in module test_fixtures - tearDownModule()
----------------------------------------------------------------------
Ran 2 tests in 0.067s
OK (SKIP=1)
See the post unittest fixture syntax and flow reference for the source and a discussion of unittest style fixtures.
I’m not posting the output for the error cases, mostly because it’s long and boring.
However, I did verify that the proper control flow in failure cases is upheld when unittest tests are run with nose.