Python Mocking with unitest.mock 2

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

Internal

Mocking a Method

The general approach is to replace at runtime the real method instance associated with the class instance to be tested with a Mock instance, configured to simulate various behaviors of the real method.

Assuming there is a class SomeClass that has a method some_method() whose behavior we want to simulate during testing


Simulating a Particular Return Value Irrespective of the Arguments it was Called With