Tech News
← Back to articles

An overly aggressive mock can work fine, but break much later

read original related products more articles

An overly aggressive mock can work fine, but then break much later. Why?

In Why your mock doesn’t work I explained this rule of mocking:

Mock where the object is used, not where it’s defined.

That blog post explained why that rule was important: often a mock doesn’t work at all if you do it wrong. But in some cases, the mock will work even if you don’t follow this rule, and then it can break much later. Why?

Let’s say you have code like this:

# user.py

def get_user_settings ():

with open ( Path ( "~/settings.json" ) . expanduser ()) as f :

return json . load ( f )

... continue reading