Intro to Python Mocks: Mocking Python Requests with Responses | Python tutorial

Veröffentlicht am: 30 Mai 2022
auf dem Kanal: Red Eyed Coder Club
14,708
217

This video is the third part of Python testing using Mocks series (or just Python Mocks). In this video we'll touch the mocking of functions that use Python Requests library with Responses library.
How to use Python Responses library to mock function, raise_for_status, exceptions.
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:   / codereyed  
Facebook: https://fb.me/redeyedcoderclub

Links:
https://github.com/getsentry/responses

Timecodes:

00:00 - Beginning.
01:31 - Writing a test for a function that should return value if JSON object with a certain structure is provided
05:50 - Testing the raise_for_status() function with Python Responses library.
06:49 - Testing a logic when Exception is raised


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
   • Intro to Python Mocks | Python tutorial  

#2 Intro to Python Mocks: Mocking Exceptions | Python tutorial
   • Intro to Python Mocks #2: Mocking Exceptio...  

#3 Intro to Python Mocks: Mocking Python Requests with Responses | Python tutorial
   • Intro to Python Mocks: Mocking Python Requ...  

How to mock requests in Python with Responses library.

#python #testing #redeyedcoderclub


Auf dieser Seite können Sie das Online-Video Intro to Python Mocks: Mocking Python Requests with Responses | Python tutorial mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Red Eyed Coder Club 30 Mai 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 14,708 Mal angesehen und es wurde von 217 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!