python unittest: can't call decorated test

前端 未结 4 972
广开言路
广开言路 2021-01-12 15:43

I have a pretty large test suite and I decorated some of the test_* functions. Now I can\'t call them by ./test.py MySqlTestCase.test_foo_double, python3.2 comp

4条回答
  •  抹茶落季
    2021-01-12 16:22

    This is a simple way of solving this issue.

    from functools import wraps
    
    def your_decorator(func):
        @wraps(func)
        def wrapper(self):
            #Do Whatever
            return func(self)
        return wrapper
    
    class YourTest(APITestCase):
        @your_decorator
        def example(self):
            #Do your thing
    

提交回复
热议问题