I encountered a problem with the availability of objects created within the decorator, and need开发者_JS百科ed in the test_case
method. My code presenting below:
def execute_results_navigation(test_case):
def wrapper(self,*args,**kwargs):
result=Result()
pagination=Pagination()
results_page_index=1
while results_page_index<=pagination.get_pages_number():
for results_object_index in range(results.get_objects_number_per_single_page()):
test_case(self,*args,**kwargs)
pagination.set_active_page_number(results_page_index)
results_page_index+=1
return wrapper
In place of test_case
method is "injected" the following code (everything takes place using predefined decorator):
@execute_results_navigation
def test_check_availability_of_search_results(self):
"""
test case 2.22
"""
offer=Offer()
result.select_hotel(results_caller["button"],results_object_index)
offer_price=offer.get_offer_object_details().price
offer.verify_offer_availability(offer_price)
offer.back_to_search_results()
test_case
method has no access to result
,pagination
objects and results_object_index
variable. All objects have been initialized when calling the decorator. Maybe I'm doing something wrong with this method, but I thought that these instances exist within the wrapper
method and access to them should not cause problems.
You won't be able to access local variables defined in wrapper within test_case.
Looks like test_check_availability_of_search_results is an instance method, so one way to solve your problem is to assign those variables to attributes of 'self'.
精彩评论