Git Product home page Git Product logo

Comments (3)

DanCardin avatar DanCardin commented on May 14, 2024 1

you can ensure python_on_whales is installed by using the "docker" extra (i.e. pip install pytest-mock-resources[docker]

from pytest-mock-resources.

DanCardin avatar DanCardin commented on May 14, 2024

the fixture is returned directly from create_redis_fixture(), so you would replace your fixture with it. like so:

redis_client = create_redis_fixture()

@pytest.fixture
def redis_client2(redis_client):  # or if you want/need to create your own client object from credentials
    yield Redis(**redis_client.pmr_credentials.as_redis_kwargs())

from pytest-mock-resources.

miguelsousa avatar miguelsousa commented on May 14, 2024

@DanCardin thanks for the feedback. Here's an updated test_myapp.py that works:

from unittest.mock import patch
from pytest_mock_resources import create_redis_fixture
from myapp import set_item, REDIS_KEY

redis_client_fixt = create_redis_fixture()

def test_set_item(redis_client_fixt):
    with patch('myapp.REDIS_CLIENT', redis_client_fixt) as redis_client:
        idx = 1234
        value = b"some_value"
        set_item(idx, value)

        assert redis_client.hget(REDIS_KEY, idx) == value

It's worth mentioning that the module python_on_whales had to be installed (python -m pip install python-on-whales) and a redis Docker image was pulled the first time the test ran.

from pytest-mock-resources.

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.