Chaining decorators with parameterized module

Viewed 100

I´m looking for help for a specific problem. We´re writing testsuites, where a testcase contains a class which contains a function. This function is our testcase. The testcases are executed by a htmltestrunner. If some testcases test similar behavoiur for different parameters, we parameterize this testcase with help of the module parameterezy - to specify: with parameterize.expand which is a wrapper. Now, to do a more efficient logging we wanted to write a function in a seperate module which is called extended logging. This should work as a wrapper for the PARAMETERIZED function.

So that means: parameterized -> WRAPS -> advanced logging -> WRAPS -> testcase function

No I wrote the following code for my advanced logging function (only for debugging and testing):

def decorator_func(func):
    print(Fore.RED +"Got into decorator_func")

    def wrapped_func(*args, **kwargs):
        print(Fore.GREEN + "Got into wrapped_func")
        
        try:
            print("Got in")
            retval = func(*args, **kwargs)
            print("Finished")

        except Exception as failure:

            print("FAILURE: " + str(failure))

            if type(failure) == AssertionError:
                print("ASSERTION ERROR")
                raise

            else:
                raise

        return retval
    return wrapped_func

The function works when I don´t use the parameterized wrapper for parameterizing my testcases. If I use the parameterized wrapper, I geht the failure: 'NoneType' object is not callable.

Can anyone help me please? Was searching the whole day.

EDIT: I already found out, that parameterized.expand returns "NoneType Object". Is there any way to get the decorated function from parameterized.expand as return?

1 Answers

I fixed the issue by adding @wrap(func) over my inner function:

def decorator_func(func):
    print(Fore.RED +"Got into decorator_func")

    @wrap(func)  

    def wrapped_func(*args, **kwargs):
        print(Fore.GREEN + "Got into wrapped_func")
        
        try:
            print("Got in")
            retval = func(*args, **kwargs)
            print("Finished")

        except Exception as failure:

            print("FAILURE: " + str(failure))

            if type(failure) == AssertionError:
                print("ASSERTION ERROR")
                raise

            else:
                raise

        return retval
    return wrapped_func

I am not aware why it works, but it does.

Related