python
install_error
ai_generated
true
fixture 'mocker' not found available fixtures: cache, capfd, capsys, ...
ID: python/pytest-mock-not-installed
80%Fix Rate
90%Confidence
0Evidence
2024-03-27First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
Root Cause
The `mocker` fixture is provided by pytest-mock, which is not installed or not in the active environment.
generic中文
`mocker` fixture 由 pytest-mock 提供,但未安装或不在当前激活的环境中。
Workarounds
-
98% success
pip install pytest-mock # or poetry add --group dev pytest-mock # or uv add --dev pytest-mock
-
90% success
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()
Dead Ends
Common approaches that don't work:
-
95% fail
mock is a module, not a fixture; pytest tries to resolve it as a fixture and fails.
-
90% fail
Returns the module, not a MagicMock controller; tests expecting `mocker.patch` fail with AttributeError.
-
90% fail
pytest runs in the currently active env; installing elsewhere doesn't make the fixture available.