r/programminghelp • u/[deleted] • Mar 31 '21
Python What is mock and patch() for python unit tests?
I am writing a unit test for the first time and I am supposed to figure this out by my self. I am utterly confused cuz I dont know the first thing about writing a unit test. Especially mock and patch().
What is it?
Why do we use it ?
What is the difference between mock and patch?
I've tried reading documentations on python website , tried watching youtube videos( after which I feel a little familiarized. But it is still useless for me ). I really feel stuck right now. :(
6
Upvotes
1
u/miketwo345 Apr 20 '21
I'm 2 weeks late on this, but I have a video explaining mocks. It might be helpful.
3
u/[deleted] Mar 31 '21
https://realpython.com/python-mock-library/
Follow that tutorial from step one all the way down and it should all make complete sense by the end.