Complete the code to define an async fixture using pytest-asyncio.
import pytest @pytest.fixture async def sample_fixture(): await [1]() return 42
The async fixture must await an async function. asyncio.sleep(0) is an async call that pauses briefly.
Complete the code to mark the test function as async to use the async fixture.
import pytest @pytest.mark.asyncio async def test_example([1]): result = await sample_fixture assert result == 42
async def.The test function must accept the fixture name as a parameter to use it. The fixture is named sample_fixture.
Fix the error in the async fixture by adding the missing decorator.
import pytest async def [1](): await asyncio.sleep(0.1) return 'done'
@pytest.mark.asyncio instead of @pytest.fixture for fixtures.Async fixtures require the @pytest.fixture decorator to be recognized by pytest.
Fill both blanks to create an async fixture that yields a resource and cleans up after the test.
import pytest @pytest.fixture async def resource(): res = await setup_resource() yield [1] await [2](res)
The fixture yields the resource res and then calls cleanup_resource(res) to clean up.
Fill all three blanks to write a test using an async fixture and assert the awaited result.
import pytest @pytest.mark.asyncio async def test_resource([1]): result = await [2] assert result == [3]
The test receives the fixture resource, awaits it, and asserts the result equals 'done'.