unit testing class hierarchies
Demian Brecht
demianbrecht at gmail.com
Tue Oct 2 14:06:42 EDT 2012
Am I missing something? Is there something that wasn't answered by my reply
about using mixins?
from unittest import TestCase
class SharedTestMixin(object):
def test_shared(self):
self.assertNotEquals('foo', 'bar')
class TestA(TestCase, SharedTestMixin):
def test_a(self):
self.assertEquals('a', 'a')
class TestB(TestCase, SharedTestMixin):
def test_b(self):
self.assertEquals('b', 'b')
$ nosetests test.py -v
test_a (test.TestA) ... ok
test_shared (test.TestA) ... ok
test_b (test.TestB) ... ok
test_shared (test.TestB) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.001s
OK
This seems to be a clear answer to the problem that solves the original
requirements without introducing error-prone, non-obvious solutions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20121002/5f9adf6a/attachment.html>
More information about the Python-list
mailing list