When there is significant overlap in the test setup, it can store DRY stuff for inheritance use. But this causes problems with unnecessary duplication of test execution:
from unittest import TestCase class TestPotato(TestCase): def test_in_parent(self): print 'in parent' class TestSpud(TestPotato): def test_in_child(self): print 'in child'
Testing of this module is performed by test_in_parent twice.
$ python -m unittest example in parent .in child .in parent . ---------------------------------------------------------------------- Ran 3 tests in 0.000s OK
Why? Is it for design? Is it possible to disable it by setting up a test runner in a certain way?
I can solve this problem by moving the setting to an unclosed class, and then use multiple inheritance, but it seems to be a bit hacked and unnecessary.
Note: the same problem occurs for other runners such as nose ( nosetests -s example.py ) and pytest ( py.test example.py )
source share