lundi 7 décembre 2015

UnitTest Python Mock first call to method, second call go as usaual

I am mocking a method; I want to raise exception on the first call, and on exception I am calling that method again with different params, so I want the second call to be process normally. What I need to do?

Code

Try 1

with patch('xblock.runtime.Runtime.construct_xblock_from_class', Mock(side_effect=Exception)):

Try 2

with patch('xblock.runtime.Runtime.construct_xblock_from_class', Mock(side_effect=[Exception, some_method])):

On second call some_method is retuned as it is, and data is not processed with different params.

Aucun commentaire:

Enregistrer un commentaire