# fixture 'mocker' 未找到
可用 fixtures: cache, capfd, capsys, ...

- **ID:** `python/pytest-mock-not-installed`
- **领域:** python
- **类别:** install_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

`mocker` fixture 由 pytest-mock 提供，但未安装或不在当前激活的环境中。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (98% 成功率)
   ```
   pip install pytest-mock
# or
poetry add --group dev pytest-mock
# or
uv add --dev pytest-mock
   ```
2. **** (90% 成功率)
   ```
   from unittest import mock

def test_x():
    with mock.patch('myapp.views.requests.get') as m:
        m.return_value.json.return_value = {}
        myapp.views.fetch()
   ```

## 无效尝试

- **** — mock is a module, not a fixture; pytest tries to resolve it as a fixture and fails. (95% 失败率)
- **** — Returns the module, not a MagicMock controller; tests expecting `mocker.patch` fail with AttributeError. (90% 失败率)
- **** — pytest runs in the currently active env; installing elsewhere doesn't make the fixture available. (90% 失败率)
