Adam Johnson
Read post

Python: inspect unittest.mock calls with attached mocks

When testing with Python's unittest.mock, you can assert on the order of calls across multiple mocked functions using attached mocks. For class methods, child mocks are automatically attached to the parent mock, so mock_calls records all calls in sequence. For separate module-level functions, you must manually use attach_mock() to link each mock to a bare parent mock, which then collects all calls in a unified timeline. The post demonstrates both scenarios with concrete code examples using create_autospec and mock.patch.object.

    #python#testing
Jul 27•3m read time•From adamj.eu
Post cover image
Table of contents
Separate functions need attach_mock()Fin
116 Impressions
Adam Johnson's image
Adam Johnson

AdamJ's platform covers topics related to software development, technology trends, and coding tutor...

54 Followers

•

444 Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard