5
私は、基本クラスで、次のデコレータていますインポートのみクラスの静的メソッド
class BaseTests(TestCase):
@staticmethod
def check_time(self, fn):
@wraps(fn)
def test_wrapper(*args,**kwargs):
# do checks ...
return test_wrapper
、次のクラスがBaseTests継承:
from path.base_posting import BaseTests
from path.base_posting.BaseTests import check_time # THIS LINE DOES NOT WORK!
class SpecificTest(BaseTests):
@check_time # use the decorator
def test_post(self):
# do testing ...
私はSpecificTestでデコレータを使用したいですBaseTests.check_timeを使わなくても元のコードに長い名前が付いているので、これを多くの場所で使う必要があります。何か案は?
EDIT: 私はCHECK_TIME BaseTestsファイル内の独立した機能作ることを決めた、と単純に
from path.base_posting import BaseTests, check_time
よろしくお願いいたします。メソッドを直接インポートするソリューションを探していましたが、あなたの提案も同様に機能します。 – Alex