Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README lock example is not clear #33

Open
nilsguillermin opened this issue Feb 23, 2023 · 0 comments
Open

README lock example is not clear #33

nilsguillermin opened this issue Feb 23, 2023 · 0 comments

Comments

@nilsguillermin
Copy link

nilsguillermin commented Feb 23, 2023

I'm sorry, I don't really understand how to read the "Mocks & Shared Resources" example in the readme. Is it missing the code for access_shared_resource()? Can we clarify how lock is used?

import asyncio
import pytest
from pytest_asyncio_cooperative import Lock

my_lock = Lock()

@pytest.fixture(scope="function")
async def lock():
    async with my_lock():
        yield

@pytest.mark.asyncio_cooperative
async def test_a(lock, mocker):
    await asyncio.sleep(2)
    mocker.patch("service.http.on_handler")
    access_shared_resource()
    assert my_fixture == "XXX"

@pytest.mark.asyncio_cooperative
async def test_b(lock, mocker):
    await asyncio.sleep(2)
    mocker.patch("service.http.on_handler")
    access_shared_resource()
    assert my_fixture == "XXX"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant