jeudi 15 septembre 2016

Make unittest.mock.Mock() return list of dicts

I'm trying to mock a call of method extra_get() which usually returns a list of dicts. As far as I understand from the Mock docs, if I want to return iterable, I should set side_effect param.

client.extra_get = mock.Mock(
            **{'side_effect': [{'foo': 'bar'}]})

But when I use the result returned by mocked client.extra_get(), I find out that it returned {'foo': 'bar'} and not the list with this dict. What I'm doing wrong? How can I make Mock method return a list of dicts?

Aucun commentaire:

Enregistrer un commentaire