Monkey-patch built-in function for a single test?

I do not want to create real files in my unittest. Therefore, I often find myself in the yard with a meaningless template and the creation of false factories for pseudo files. I was thinking if it would not be better to avoid (in this case) these senseless efforts and try something like the scope of the local unittest method:

open = lambda x: StringIO() 

Will it be okay? Or are there major reservations / do not go out in this approach and better with breadboard factories?

+6
source share
1 answer

This is great if you understand how python areas work (i.e. locally normal, globally cause problems).

You should probably also bear in mind that your monkey filters will have different modes of rejection of originals and have appropriate tests to make sure your code interacts correctly with the built-in functions.

+4
source

Source: https://habr.com/ru/post/908553/


All Articles