Intro to Python Mocks | Python tutorial

preview_player
Показать описание
How to write Python tests for functions that make a request to external API.
It's a Python unittest mock tutorial for beginners.

Follow me @:

Timecodes:

00:00 - ideal testable function, and a unit test for it.
02:29 - example of a function with a dependency on another function.
06:02 - a test for the function with a dependency on another function. Problems that Mocks will solve.
11:28 - an example of unit test of a function that makes a request to external API and returns a different result each time it's been called. A mock returns another mock. How to test requests.

Why Python mocks are important:
- Mocks eliminate dependency on network, database calls, calls to OS (it will speed testing)
- we get isolated unit tests,
- we can test methods that have no return value
- reduce test complexity. We don't have to write complex logic to handle behavior of methods under tests.
- don't have to wait to implement other methods.

When should you mock?
When you don't want to actually call an object

Intro to Python Mocks | Python tutorial

#python #testing #redeyedcoderclub
Рекомендации по теме
Комментарии
Автор

It's an amazing video! You have really broken the concepts into very easily understandable components. Loved your way of explanation! Thanks

vikrantmahajan
Автор

Really great tutorial! From having little to no idea about how Python Mocks works to now having a good understanding. Time to improve my understanding now through practice, thank you!

JedLearns
Автор

That's just what i needed right now. Oleg, thank you!
Been watching your channel since 2017, some time supported on patreon, your content never disappoints. You make very clear and understandable explanation on every important nuance, incrementally from easy to advanced stuff. Sometimes I miss, when there are no new videos for a long time :) Big thank you anyway. I personally think that you made a huge, or even biggest contribution(not size, but in terms of quality, for sure) into instructional videos for Russian self-taught python developers, and now for International community. Time ago your videos helped me to learn a lot of things, to get a first paid developer job and etc.
Legend!

sergeyshevtsov
Автор

Fantastic tutorial. Took me from almost no knowlege of python unittest and mocks to very confident. Thank you!

roberto_camp
Автор

Amazing work! Never thought of pronouncing OK as Awk.

aamirsuleman
Автор

THATS what happened to your previous channel. Such a great surprise to occasionally find out that you are not done with youtube.
Since me watching my first video on your channel many things happened, and even after all those years i can definitely say that your material is way beyond the others in terms of quality.

Keep it up man

AlexeyLebedev-vh
Автор

You're a saviour man. I had issues with DI and mocks but this video has simplified everything for me. Great explanation!👏

bonnymunga
Автор

No one in YouTube was able to explain this mock with such a simple example. If I could request would you be able to make a series on testing AWS services using mock.

diwakardayalan
Автор

This video is just awesome. I was stuck reading docs and couldn't apply it in my test cases. Thanks a lot for this great explanation.

TheSirgo
Автор

Excellent. I was breaking my head on mock and patch.. now its crystal clear.

AVISH
Автор

One of the best vedioes on Python Mocks👏👏👏

bikkinarohith
Автор

this is great video, with this one video i wrote my 1st unit test case of my project. Thanks

vibhourjain
Автор

Great explanation. Was struggling with the concept. Now I am confident with the topic

aashrayzaveri
Автор

Excellent video - great examples - so simple, but complete, I agree with others that your commentary is incredible. You describe what is going on at every step - both in the code and in the underlying logic. Mocks can be confusing to me and you really help break down the concepts so thoroughly. This is my first experience watching videos by you. I will be back for more! PS - I usually use pytest, but it was helpful to see the more traditional unittest methodology applied to mocks. Translating your code to pytest was a good exercise for a newbie like me.

williamgillett
Автор

Your work is excellent, you help me a lot, thank you!

ОксанаХлопотина-ып
Автор

Amazing video. Simplified demo on how to write UT with mocks. Thanks

brajesh
Автор

hi, i have seen many and many tutos python mocks, but this one is simple, clear and understable. 👍 and many thanks !

philveo
Автор

I'm taking courses that have this topic. I didn't understand anything there at all. However, as soon as I watched the first 10 minutes of your video, everything immediately became clear. Thank you very much!

_KREKHOVETSKYI_
Автор

Thanks for the explanation. The mock is very powerful. I feel conformable starting to use it now

rugmaable
Автор

I get a lot of knowledge by watching your video lessons. Thank you very much!

КсюшаМаркина-эн