RUVIDEO
Поделитесь видео 🙏

Intro to Python Mocks #2: Mocking Exceptions | Python tutorial

This video is the second part of Python testing using Mocks series (or just Python Mocks). In this video we'll touch the mocking of exceptions topic, how to mock exceptions in Python, how to mock the .raise_for_status() function of the Requests library.
In this Python testing tutorial as an example I use a function that makes a request to external API. And as a testing library I use unittest.
It's a Python unittest mock tutorial for beginners.

Follow me @:
Telegram: https://t.me/red_eyed_coder_club
Twitter: https://twitter.com/CoderEyed
Facebook: https://fb.me/redeyedcoderclub

Timecodes:

00:00 - Beginning. Adding try/except block to the function under test
02:19 - How to raise an exception from a test, and how to mock an exception using the .side_effect property.
04:23 - Fixing the 'TypeError: catching classes that are not inherit from BaseException is not allowed' when mocking an exception.
07:03 - Using the .raise_for_status() function from the requests library
09:48 - Writing a test to test raise_for_status(), and mocking raise_for_status
13:32 - Checking status codes within an except clause of the try/except block.


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


#1 Intro to Python Mocks | Python tutorial
https://youtu.be/xT4SV7AH3G8

#2 Intro to Python Mocks: Mocking Exceptions | Python tutorial
https://youtu.be/RqR0AvEujrU


#python #testing #redeyedcoderclub

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Intro to Python Mocks #2: Mocking Exceptions | Python tutorial», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.