Complete the code to define a fixture in conftest.py that returns a simple string.
import pytest @pytest.fixture def [1](): return "hello"
The fixture name should be a valid Python function name that describes the data it provides. Here, greeting is a clear and appropriate name.
Complete the code to use the fixture in a test function in a separate test file.
def test_example([1]): assert [1] == "hello"
The test function receives the fixture name as a parameter to use its returned value. Here, greeting matches the fixture defined in conftest.py.
Fix the error in the fixture definition to make it shared across multiple test files.
import pytest @pytest.fixture def [1](): return 42
To share a fixture across multiple test files, it must be decorated with @pytest.fixture. The missing decorator causes the fixture not to be recognized.
Fill both blanks to correctly import pytest and define a fixture that returns a list.
[1] @pytest.fixture def sample_list(): return [2]
You must import pytest to use its fixture decorator. The fixture returns a list, so the return value should be a list literal.
Fill all three blanks to define a fixture with scope 'module' and use it in a test function.
import pytest @pytest.fixture(scope=[1]) def config(): return {"url": "http://example.com"} def test_url([2]): assert [3]["url"] == "http://example.com"
The fixture scope is set to 'module' to share it across tests in the module. The test function receives the fixture named 'config' as a parameter and uses it to assert the URL.