Get the latest tech news

“Don’t mock what you don't own” in 5 minutes (2022)


A common issue when writing tests for real-world software is how to deal with third-party dependencies. Let’s examine an old, but counter-intuitive principle.

It takes an HTTP client (in this case, I use the excellent httpx package) and returns a dictionary of repository names that point to a list of the version tags. I use the spec_set argument ( as should you) to prevent unittest.mock.Mock from happily returning new mocks when you access any attribute, and yet constructs like this tend to be brittle and unpleasant to create and debug. This point can’t be overstated: In an attempt to simplify our mocks by following a counter-intuitive principle from ancient times, we’ve improved our business logic.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of minutes

minutes

Related news:

News photo

Amazon Doubles Prime Video Ads to 6 Minutes Per Hour

News photo

Build a minimal decorator with Ruby in 30 minutes

News photo

EXCLUSIVE: Amazon Doubles Prime Video Ads to 6 Minutes Per Hour