Code Monkey home page Code Monkey logo

Comments (17)

nicoddemus avatar nicoddemus commented on May 10, 2024 95

Hi @Dishanka13, did you install pytest-mock using pip install pytest-mock?

You can verify that by calling pip list

from pytest-mock.

BlackestDawn avatar BlackestDawn commented on May 10, 2024 5

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.

from pytest-mock.

SmartManoj avatar SmartManoj commented on May 10, 2024 2

Hi @Dishanka13, did you install pytest-mock using pip install pytest-mock?

You can verify that by calling pip list

After that reopening terminal solved

from pytest-mock.

Hettomei avatar Hettomei commented on May 10, 2024 1

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 done pip install ... or update pip install -r requirements-dev.txt

My solution was to create a new pyenv and to create a new virtualenv + pip install -r requirements-dev.txt and then everything worked.

thanks @BlackestDawn you helped me understand this.

from pytest-mock.

nicoddemus avatar nicoddemus commented on May 10, 2024

I think I know what's happening.

I see you are defining a fixture named request. The problem is that pytest also has a builtin fixture named request which is used for a lot of things like getting options, the name of the test being executed, registering finalizers, etc.

Before version 1.4.0, the mocker fixture didn't depend on other fixtures, but on 1.4.0 due to the new mock_use_standalone_module configuration option it now depends on the builtin request fixture to lookup the option's value. So the mocker fixture asks for a request fixture and gets your fixture definition instead, which in turn also depends on mocker so the "mocker fixture stack" blows and pytest assumes that there's no mocker fixture (we should improve that message somehow).

I see a few possibilities:

  1. Rename request to something else (myrequest?); as you can see it is an important fixture so it may break in unexpected ways, so that's what I would do;
  2. Your request fixture doesn't even use mocker, so you may take out the parameter and things should just work (for now).

Hope that makes sense, let me know if you have any questions.

from pytest-mock.

jaimemarijke avatar jaimemarijke commented on May 10, 2024

Thanks for the speedy reply and explanation! I will try this out and let you know if it fixes my problem.

+1 for improving the error message :). It was confusing that the error was that "fixture 'mocker' not found" but that "mocker" was listed in available fixtures.

from pytest-mock.

nicoddemus avatar nicoddemus commented on May 10, 2024

Sure, let me know how that goes so we can close this if one of the solutions is good enough.

from pytest-mock.

jaimemarijke avatar jaimemarijke commented on May 10, 2024

Looks like removing the unused 'mocker' fixture fixed the problem, thanks again!

If you do close this, should I open a separate issue for improving the error message?

from pytest-mock.

nicoddemus avatar nicoddemus commented on May 10, 2024

Yes please. 😁

Closing this then.

from pytest-mock.

Dishanka13 avatar Dishanka13 commented on May 10, 2024

can anyone help me with this error
def test_getproject(mocker):
conversationService = ConversationService()
mocker.patch.object(conversationService ,'getDoc()',return_value="None")
assert conversationService.getDoc()==None
res=DialogueService.getproject()
assert res=="None"
am getting error as
def test_getproject(mocker):
E fixture 'mocker' not found

  available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory

from pytest-mock.

dilnasaran avatar dilnasaran commented on May 10, 2024

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.

thanks @BlackestDawn . This helped me solve my issue. Do you have any idea why this is needed?

from pytest-mock.

The-Compiler avatar The-Compiler commented on May 10, 2024

@BlackestDawn @dilnasaran Are you sure pytest is really picking up your virtualenv's pytest? Using pytest --version --version should tell you where it was imported from and which plugins it found.

from pytest-mock.

dilnasaran avatar dilnasaran commented on May 10, 2024

@BlackestDawn @dilnasaran Are you sure pytest is really picking up your virtualenv's pytest? Using pytest --version --version should tell you where it was imported from and which plugins it found.

@The-Compiler I just checked it , pytest is being imported from the virtualenv.

from pytest-mock.

The-Compiler avatar The-Compiler commented on May 10, 2024

What about the pytest-mock plugin if you don't install it user-wide? Is it listed there? Is it listed in python3 -m pip freeze (with the virtualenv's python3)?

from pytest-mock.

dilnasaran avatar dilnasaran commented on May 10, 2024

@The-Compiler Yes, the pytest-mock plugin is listed in the virtualenv and still I had the error "fixture 'mocker' not found". It only stopped appearing after I installed pytest-mock it in the user wide python.

from pytest-mock.

The-Compiler avatar The-Compiler commented on May 10, 2024

@dilnasaran In a recent version? The mock fixture was renamed to mocker in 0.4.0.

from pytest-mock.

nikhilteja91 avatar nikhilteja91 commented on May 10, 2024

Hi @Dishanka13, did you install pytest-mock using pip install pytest-mock?

You can verify that by calling pip list

it worked. thank you.

from pytest-mock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.