mercredi 24 décembre 2014

Python unites - gathering multiple @patch decorators within another decorator

I'm writing an internal unit tests framework which involves mocking multiple functions/classes.

@patch seems to be working great for my needs, but as there are many tests that will require to patch many different classes/functions, I'm looking to avoid writing multiple @patch before every test and maybe encapsulate them all into another decorator. To better illustrate my needs:


current state:



@patch('p.A', mockedA)
@patch('p.B', mockedB)
.
.
@patch('p.N', mockedN)
def test_this()


desired state:



@patch_all
def test_this()


Is it possible to implement something like this?, so far I wasn't able to as @patch requires to be followed either def or another @.


Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire