Repaso
Español
TestingAdvancedTST-03

Which patch target makes this test intercept the HTTP call?

# app/services.py
from requests import get

def fetch_user(uid):
    return get(f"https://api.example.com/users/{uid}").json()

Options

  1. patch("requests.get")
  2. patch("app.services.get") (Correct option)
  3. patch("requests.api.get")
  4. patch("get")

Answer

patch("app.services.get")

Why

from requests import get creates a NEW name get inside the module app.services, pointing to the function.

patch("requests.get") replaces the name inside the requests module, but app.services.get still points to the original function, so the real HTTP call happens.

Rule: patch the name where it is USED (looked up), not where it is defined.

Remember

Patch where the name is looked up.

Key terms

Practice this question in Repaso