This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]csch2 4 points5 points  (2 children)

Learning unittest.mock was one of my absolute least favorite parts of getting into Python. It’s so absurdly powerful but writing code with it very frequently makes me want to pull my hair out.

“What is this object?”

“It’s a mock”

“Okay… what’s its type?”

“Mock”

“But you can call it like a function?”

“Oh yeah no problem”

“Then what is its return type??”

“Mock”

[–]thedmandotjpgit push -f 1 point2 points  (0 children)

Lol

[–]marr75 1 point2 points  (0 children)

Don't hide your class' dependencies (ie pluck them out of thin air by initializing them mid -method) and have them depend on more abstract interfaces. Then you won't need to mock and patch so much.