what is mocking the are different types of mock includingtest stubs test stub is typically hand coded functionmethod or object used for testing purposes the behaviour implemented by test stub may represent limited sub set of the functionality of the real thing fakes fakes typically provide addition functionality compared with test stub fakes may be considered to be test specific version of the real thingsuch as an in memory database used for testing rather than the real database such fakes typically still have some limitations on their functionalityfor example when the tests are terminated all data is purged from the in memory database rather than stored permanently on disk autogenerated test mocks these are typically generated automatically using supporting framework as part of the set up of the test the expectations associated with the test mock these expectations may specify the results to return for specific inputs as well as whether the test mock was called etc test mock spy if we are testing particular unit and it returns the correct result we might decided that we do not need to consider the internal behaviour of the unit howeverit is common to want to confirm that the test mock was invoked in the ay we expected this helps verify the internal behaviour of the unit under test this can be done using test mock spy such test mock records how many times it was called and what the parameters used where (as well as other informationthe test can then interrogate the test mock to validate that it was invoked as expected/as many times as expected/with the correct parameters etc common mocking framework concepts as has been mentioned there are several mocking frameworks around for not only python but other languages such as javacand scala etc all of these frameworks have common core behaviour this behaviour allows mock functionmethod or object to be created based on the interface presented by the real thing of course unlike languages such as cand java python does not have formal interface concepthowever this does not stop the mocking framework from still using the same idea in general once mock has been created it is possible to define how that mock should appear to behavein general this involves specifying the return result to use for function or method it is also possible to verify that the mock has been invoked as expected with the parameters expected the actual mock can be added to test or set of tests either programmatically or via some form of decorator in either case for the duration of the test the mock will be used instead of the real thing