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

来源:互联网 发布:remark软件 编辑:程序博客网 时间:2024/06/11 00:50
使用装饰器,在每条用例之前需要对手机清log
tool.pydef LogClear(fn):    def wrapper():        os.system("adb logcat -c")        print 'logclear'        fn()    return wrapper

Calc.pyclass 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.pydef LogClear(fn):    def wrapper(self):        os.system("adb logcat -c")        print 'logclear'        fn(self)    return wrapper


0 0