Mocking an Imported Function
A pytest mock patches the wrong target, so the real function still runs.
Codepython
# service.py
from utils import fetch_data
def process():
return fetch_data() * 2
# test_service.py
from unittest.mock import patch
import service
@patch("utils.fetch_data")
def test_process(mock_fetch):
mock_fetch.return_value = 5
assert service.process() == 10Why does this test fail to mock fetch_data as intended?