I'm using unittest and nose-parametarized, and want to apply different decorators to a test based on a condition.
I have a test and I want to skip unittest.skip
the test or execute it @parameterized.expand(args)
based on the arguments passed to args.
I think I need to have another decorator which applies proper decorator to the test , but now sure how.
pseudo code could be something like this :
@validate_data(args)
def test(args):
...
where @validate_data(args)
is a decorator which applies unittest.skip
if args ==None or @parameterized.expand(args)
otherwise
Any comments/suggestions is appreciated.
A decorator can also be called as a function.
@decorator
is equivalent todecorator(func)
and@decorator(args)
todecorator(args)(func)
. So you could return the value of those function returns conditionally in your decorator. Here is an example below: