I'm getting some integration tests running against the database, and I'd like to have a structure that looks something like this:
class OracleMixin(object):
oracle = True
# ... set up the oracle connection
class SqlServerMixin(object):
sql_server = True
# ... set up the sql server connection
class SomeTests(object):
integration = True
# ... define test methods here
class test_OracleSomeTests(SomeTests, OracleMixin):
pass
class test_SqlServerSomeTests(SomeTests, SqlServerMixin):
pass
This way, I can run SQL Server tests and Oracle tests separately like this:
nosetests -a oracle
nosetests -a sql_server
Or all integration tests like this:
nosetests -a integration
However, it appears that nose will only look for attributes on the subclass, not on the base class. Thus I have to define the test classes like this or the tests won't run:
class test_OracleSomeTests(SomeTests, OracleMixin):
oracle = True
integration = True
class test_SqlServerSomeTests(SomeTests, SqlServerMixin):
sql_server = True
integration = True
This is a bit tedious to maintain. Any ideas how to get around this? If I was just dealing with one base class, I'd just use a metaclass and define the attributes on each class. But I get an uneasy feeling about having a metaclass for the test class, a metaclass for Oracle, and a metaclass for SQL Server.