lundi 30 mai 2016

How to get a unittest.mock.sentinel act as a string instance?

I am writing some unit tests for a library which populates data from a dictionary.

I want to check that the populated data is correct according to the dictionary, and I use sentinels to identify the data.

However, the library is written with a check that the parameter is an instance of a string (isinstance(foo, str)), and the sentinel obviously doesn't pass this test.

Is there a way to get the sentinel be considered as an instance of a string? I already tried unittest.mock.sentinel.foo.__class__ = str, but these objects don't work as well as mocks.

Aucun commentaire:

Enregistrer un commentaire