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

Red Eyed Coder Club
Red Eyed Coder Club
16.7 هزار بار بازدید - 2 سال پیش - This video is the second
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: https://www.seevid.ir/fa/w/RqR0AvEujrU - Beginning. Adding try/except block to the function under test https://www.seevid.ir/fa/w/RqR0AvEujrU - How to raise an exception from a test, and how to mock an exception using the .side_effect property. https://www.seevid.ir/fa/w/RqR0AvEujrU - Fixing the 'TypeError: catching classes that are not inherit from BaseException is not allowed' when mocking an exception. https://www.seevid.ir/fa/w/RqR0AvEujrU - Using the .raise_for_status() function from the requests library https://www.seevid.ir/fa/w/RqR0AvEujrU - Writing a test to test raise_for_status(), and mocking raise_for_status https://www.seevid.ir/fa/w/RqR0AvEujrU - 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://www.seevid.ir/fa/w/xT4SV7AH3G8 #2 Intro to Python Mocks: Mocking Exceptions | Python tutorial https://www.seevid.ir/fa/w/RqR0AvEujrU #python #testing #redeyedcoderclub
2 سال پیش در تاریخ 1401/02/28 منتشر شده است.
16,749 بـار بازدید شده
... بیشتر