24 Nisan 2022 Pazar

How to mock socket object used with "with" keyword on python Unit Tests

In a development process, you have to make sure that all your working code have to remain as working as intended to be. Just like when you first wrote them. So maybe you think that you have to write unit test for your functions, classes, etc. But most of the time you have to isolate your application from external and variable inputs. In a situation like this, you will basically use mocking mechanisms to set inputs that outside from the units (outside from a function or class).

So let's start with basic mocking example and see how it goes.