示例工程 29-testing-pytest
29-testing-pytest/04-patch-target/README.md
# 04 · patch-target
**演示**:`mock.patch` 必须打在使用处(`data_service.fetch`),而不是定义处(`data_client.fetch`);打错位置测试仍拿到真实值。
**运行**:
```sh
uv run pytest examples/29-testing-pytest/04-patch-target -q
```
**预期输出**(3.12.9):
```text
.... [100%]
```
**依赖**:pytest(dev 组)。
**注意**:`autospec=True` 会按原函数签名校验调用;`patch` 目标用「模块.属性」字符串,避免直接替换导入对象。