python 使用装饰器提示:TypeError: wrapper() takes no arguments (1 given)

使用 装饰器,在每条用例之前需要对 手机清log
tool.py
def LogClear(fn):
    def wrapper():
        os.system("adb logcat -c")
        print 'logclear'
        fn()
    return wrapper

Calc.py
class Calc(unittest.TestCase):
    @LogClear
    def test_calc(self):
        self.driver.start_activity('com.google.android.calculator','com.android.calculator2.Calculator')
         self.driver.find_element_by_id("com.google.android.calculator:id/digit_4").click()
        res =self.driver.find_element_by_id("com.google.android.calculator:id/formula").text
        AssertAct(self, res,'5','the result of calc is not correct',get_mod())

执行,提示:TypeError: wrapper() takes no arguments (1 given)
其实要添加在装饰器上添加一个参数:

tool.py
def LogClear(fn):
    def wrapper(self):
        os.system("adb logcat -c")
        print 'logclear'
        fn(self)
    return wrapper


你可能感兴趣的:(python 使用装饰器提示:TypeError: wrapper() takes no arguments (1 given))