您的位置:首页 > 移动开发

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

2017-01-10 14:02 806 查看
使用装饰器,在每条用例之前需要对手机清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.pydef LogClear(fn):def wrapper(self):os.system("adb logcat -c")print 'logclear'fn(self)return wrapper
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐