I am aware of the importance of path to mock as illustrated here, but consider this Django scenario
models.py
class Proxmox(Model):
@property
def api(self, ...):
....
tasks.py
def run_task(...):
....
views.py
from models import Proxmox
from tasks import run_task
class APIView(...):
...
Proxmox.objects.get(...).api.do_something()
run_task()
tests.py
class MyTestCase(...):
@mock.patch('tasks.run_task') <---- this is not patched as already imported in view
#@mock.patch('views.run_task'). <---- this patches fine
@mock.patch('models.Proxmox.api') <---- but why this works fine?
def test_one(self, mock_api, mock_run_task):
client.get(....)
...
Both Proxmox
and run_task
are imported into views.py
so why patching models.Proxmox.api
still got patched?