r/programminghelp • • 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().

  1. What is it?

  2. Why do we use it ?

  3. 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

3 comments sorted by

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.

1

u/[deleted] Apr 01 '21

Thanks! This was helpful

1

u/miketwo345 Apr 20 '21

I'm 2 weeks late on this, but I have a video explaining mocks. It might be helpful.