Skip to content
Advertisement

How to decorate a parent class and make child classes use it? python

What I want is to create a class decorator to decorate a class and works on subclasses too.

Imagine this class:

JavaScript

and the real Test:

JavaScript

what I want is to use a decorator in CustomBaseTest that finds all methods that starts with ‘decoratte_this_’ and execute custom code after and before. I already have the decorator, something like this:

JavaScript

do you know if is possible to do that? and how?

thanks!!!

Advertisement

Answer

Thanks to @Markku and @BrenBarn.

Here is the solution.

First we have a simple decorator:

JavaScript

And the metaclass:

JavaScript

And that worked for me!

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement