Complete the code to define a fixture factory that returns a function creating user dictionaries.
import pytest @pytest.fixture def user_factory(): def create_user(name): return {'name': [1] return create_user
The inner function create_user takes name as argument and returns a dictionary with key 'name' and value from the argument name. So the blank should be filled with name.
Complete the code to use the fixture factory in a test function.
def test_user_creation(user_factory): user = user_factory([1]) assert user['name'] == 'Alice'
The test expects the user name to be 'Alice'. So the factory should be called with the string 'Alice' to create the user.
Fix the error in the fixture factory to correctly accept an optional age parameter with default 30.
import pytest @pytest.fixture def user_factory(): def create_user(name, age=[1]): return {'name': name, 'age': age} return create_user
The default value for the age parameter should be the integer 30, not a string or variable name.
Fill both blanks to create a fixture factory that returns a user with a default city and allows overriding it.
import pytest @pytest.fixture def user_factory(): def create_user(name, city=[1]): return {'name': name, 'city': [2] return create_user
The default city should be the string 'New York'. The dictionary value should use the parameter city to allow overriding.
Fill all three blanks to create a fixture factory that returns a user dictionary with name, age, and city, where age defaults to 25 and city defaults to 'Boston'.
import pytest @pytest.fixture def user_factory(): def create_user(name, age=[1], city=[2]): return {'name': name, 'age': [3], 'city': city} return create_user
The default age is the integer 25, the default city is the string 'Boston', and the dictionary uses the variable age for the age value.