Originally published at recca0120.github.io from utils import sum, then patch('utils.sum') — and the mock never takes effect. Switch to patch('helloworld.sum') and it works. This is the most common Python mock mistake. Once you understand why, you won't hit it again. Reproducing the Problem utils.py: def sum(a, b): return a + b helloworld.py: from utils import sum def main(): return sum(1,
Python Mock Pitfall: Patch Where It Is Used, Not Where It Is Defined
Recca Tsai·Dev.to··1 min read
D
Continue reading on Dev.to
This article was sourced from Dev.to's RSS feed. Visit the original for the complete story.