If you want to enhance the capabilities of the mock.Mock
class, just subclass Mock
and add your own methods.
class MyMock(Mock):
def session(self):
# Save session data here?
The mock documentation explains that when a new mock is to be created, it will be the same type as the parent. This means that the session
function will also be available on any other mocks which are created during mocking.
This doesn't cover the case where you need to dynamically attach a session
function to an existing mock object.