pytest-mock: fixture 'mocker' not found
I haven’t looked too closely into this bug yet, but the error itself is strange, given that it explicitly lists ‘mocker’ as one of the available fixtures.
I had run tox -r previously and everything passed. Then I upgraded
- pytest (2.9.2) -> 3.0.3
- pytest-mock (1.2) -> 1.4.0
And started seeing this failure.
@pytest.fixture
def request(mocker):
E fixture 'mocker' not found
> available fixtures: cache, capfd, capsys, doctest_namespace, mock, mocker, monkeypatch, pytestconfig, record_xml_property, recwarn, request, requests_get, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
Code looks something like this:
import pytest
from mock import Mock, sentinel
from requests import codes
@pytest.fixture
def request(mocker):
return Mock((), url='https://test-url.com:8000', cookies=None, headers={})
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (7 by maintainers)
Hi @Dishanka13, did you install
pytest-mock
usingpip install pytest-mock
?You can verify that by calling
pip list
Not sure if still relevant but I found that I had to install pytest-mock into my user-level general python module-library (~/.local/lib/python*) when running from a venv, even though that venv had the pytest-mock package installed and relevant executables ran from the venv.
After that reopening terminal solved
FWIW
I m a newby with python.
I have to maintain an app with
pyenv
+virtualenv
I have this same error
fixture 'mocker' not found
even if I have donepip install ...
or updatepip install -r requirements-dev.txt
My solution was to create a new
pyenv
and to create a newvirtualenv
+pip install -r requirements-dev.txt
and then everything worked.thanks @BlackestDawn you helped me understand this.