In some cases for Python unit tests, we want to automatically perform setUp
methods in as declared in a base class. However, we still want setUp
to work as per normal in the subclass. The following code will proxy the new setUp
function to run it's base class' and the new one.
# Define a common test base for starting servers
class MyBaseTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
"""On inherited classes, run our `setUp` method"""
# Inspired via http://stackoverflow.com/questions/1323455/python-unit-test-with-base-and-sub-class/17696807#17696807
if cls is not MyBaseTestCase and cls.setUp is not MyBaseTestCase.setUp: