Simon Willison’s Weblog

Subscribe
Atom feed for mocking

2 items tagged “mocking”

2021

When you have to mock a collaborator, avoid using the Mock object directly. Either use mock.create_autospec() or mock.patch(autospec=True) if at all possible. Autospeccing from the real collaborator means that if the collaborator's interface changes, your tests will fail. Manually speccing or not speccing at all means that changes in the collaborator's interface will not break your tests that use the collaborator: you could have 100% test coverage and your library would fall over when used!

Thea Flowers

# 17th March 2021, 4:44 pm / mocking, python, testing

2007

Mock—Mocking and Test Utilities (via) New mocking library for Python based on the “action ... assertion” pattern (as opposed to the more common “record ... replay”).

# 20th November 2007, 11:30 pm / mocking, python, testing, unittests