データベースに対していくつかの統合テストを実行していますが、次のような構造にしたいと考えています。
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
このようにして、次のように SQL Server テストと Oracle テストを別々に実行できます。
nosetests -a oracle
nosetests -a sql_server
または、次のようなすべての統合テスト:
nosetests -a integration
ただし、鼻は基本クラスではなく、サブクラスの属性のみを検索するようです。したがって、次のようにテスト クラスを定義する必要があります。そうしないと、テストが実行されません。
class test_OracleSomeTests(SomeTests, OracleMixin):
oracle = True
integration = True
class test_SqlServerSomeTests(SomeTests, SqlServerMixin):
sql_server = True
integration = True
これを維持するのは少し面倒です。これを回避する方法はありますか?1 つの基本クラスだけを扱う場合は、メタクラスを使用して、各クラスの属性を定義します。しかし、テスト クラス用のメタクラス、Oracle 用のメタクラス、SQL Server 用のメタクラスがあることに不安を覚えます。