Byte Ebi's Logo

Byte Ebi 🍤

A Bit everyday A Byte every week

[Pytest 101] 04 Mock Class

An introduction to two approaches for testing class instantiation when using the Factory Pattern, with practical examples using pytest-mock.

Ray

Introducing the factory pattern in your code can significantly improve its structure—but it also makes unit testing a bit trickier.
We’ll walk through two different mocking strategies, compare their pros and cons, and help you write more robust tests!

[Pytest 101] 03 Mock SQL Query

Free your unit tests from database dependencies using mocks.

Ray

With mock objects, we can simulate database operations without actually connecting to a real database.
This means we don’t need to prepare a dedicated test database or worry about cleaning it up after tests.

[Pytest 101] 02 Basic Usage of Mock

How to use Mock to simulate behavior, raise exceptions, and test side effects.

Ray

After covering the basic tools, this article demonstrates how to use mocks effectively in Pytest.
Mocks allow us to replace the logic of real functions to simulate different scenarios and write more precise unit tests.
We’ll walk through examples of mocking functions, simulating errors, and even handling external dependencies like Redis.

[Pytest 101] 01 Introduction to Pytest & Mock

An introduction to Pytest and the core concepts of Mock

Ray

Writing unit tests is a well-known best practice in software development, but actually getting started often feels overwhelming.
Where do you begin? What tools should you use? And how do you use them?
For beginners, these first steps can easily become roadblocks.

Recent Posts

Categories

Tags