Import only a class static method

后端 未结 1 1299
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 16:40

I have the following decorator in a base class:

class BaseTests(TestCase):
    @staticmethod
    def check_time(self, fn):
        @wraps(fn)
        def tes         


        
相关标签:
1条回答
  • 2020-12-06 17:10

    Simply put

    check_time = BaseTests.check_time
    

    in your second module:


    from module_paths.base_posting import BaseTests
    check_time = BaseTests.check_time
    
    class SpecificTest(BaseTests):
    
        @check_time # use the decorator
        def test_post(self):
            # do testing ...
    

    You may also want to reconsider making check_time a staticmethod, since it appears your use case employs it more as a stand-alone function than as a staticmethod.

    0 讨论(0)
提交回复
热议问题