Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I am having a problem with the substitution of the variable 'insurance_mode' by the decorator. I have executed the following decorator statement:

@execute_complete_reservation(True)

def test_booking_gta_object(self):

    self.test_select_gta_object()

but unfortunately, this statement does not work. 

def execute_complete_reservation(test_case,insurance_mode):

    def inner_function(self,*args,**kwargs):

        self.test_create_qsf_query()

        test_case(self,*args,**kwargs)

        self.test_select_room_option()

        if insurance_mode:

            self.test_accept_insurance_crosseling()

        else:

            self.test_decline_insurance_crosseling()

        self.test_configure_pax_details()

        self.test_configure_payer_details

    return inner_function

1 Answer

0 votes
by (108k points)

See, the code for decorators with arguments is a bit different. The decorator with parameters will return a function that will take a method and return another method. What I mean is:

def decorator_factory(argument):

    def decorator(function):

        def wrapper(*args, **kwargs):

            funny_stuff()

            something_with_argument(argument)

            result = function(*args, **kwargs)

            more_funny_stuff()

            return result

        return wrapper

    return decorator

Want to become a Python Developer? Check out this insightful Python Certification course.

 

Related questions

0 votes
1 answer
0 votes
1 answer
+2 votes
2 answers
+9 votes
1 answer
asked Jul 30, 2019 in Python by ashely (50.2k points)

Browse Categories

...