嘿,我有一個方法定義如下:方法的參數沒有被傳遞到裝飾機
from x.y import util
class my_Class(some_object):
@util.myDecorator
def foo(self, log_file):
'''
Test that search entered into the search bar is the search being
executed in the job.
'''
self.some_page.open()
textarea = self.some_page.searchbar
searchbar.run_search(log_file.search_string)
self.browser.capture_screenshot()
self.some_page.jobstatus.wait_for_job_complete()
self.verify_equals(
self.some_page.jobstatus.event_count,
log_file.event_count,
"Event count doesn't seem to be right.")
裝飾是在文件util.py
def mydecorator(func):
def timeit(*args, **kwargs):
start_time = time.time()
ret=func(*args, **kwargs)
end_time = time.time()
print end_time - start_time
return ret
return timeit
當我嘗試執行代碼,它在ret=func(*args, **kwargs)
失敗,該錯誤消息
TypeError: foo() takes exactly 2 arguments (1 given)
- 我打印* args來的內容(與
','.join(str(each) for each in args)
),看看它包含的,它打印出來
<....my_Class object at ...>
裝飾工作正常,只有一個ARG(個體經營)方法。我在這裏錯過了什麼嗎?
你怎麼調用'foo'方法? my_Class()。FOO()? – alko
你是怎麼調用'foo()'的?這工作:'my_Class()。foo(123)'。這不是:'my_Class()。foo()'。 –
am使用py.test調用方法foo 'py.test -k foo file_name.py' – jeev