Complete the code to define a simple pytest fixture that returns a user name.
import pytest @pytest.fixture def [1](): return "Alice"
The fixture function must be named so tests can use it. Here, user_name is the correct fixture name.
Complete the code to use the fixture in a test function.
def test_greeting([1]): assert [1] == "Alice"
The test function parameter must match the fixture name to receive its value. Here, user_name is the parameter that receives the fixture value.
Fix the error in the fixture that should return a dictionary with user info.
@pytest.fixture def user_info(): return [1]"name": "Bob", "age": 30}
The fixture must return a dictionary. Dictionaries start with a curly brace {. The correct answer is {.
Fill both blanks to create a fixture that returns a list of user names and a test that uses it.
@pytest.fixture def user_list(): return [1]"Alice", "Bob", "Charlie"[2] def test_user_count(user_list): assert len(user_list) == 3
The fixture returns a list, which uses square brackets []. So the blanks are filled with [ and ].
Complete the code to create a fixture that returns a dictionary with user details and a test that checks the user's age.
@pytest.fixture def user_data(): return {"name": "Eve", [1]: 28} def test_user_age(user_data): assert user_data["age"] == 28
The fixture returns a dictionary, so it starts with { and ends with }. The key for age must be quoted as "age".