Complete the code to use a pytest fixture from conftest.py.
def test_example([1]): assert 1 + 1 == 2
The fixture defined in conftest.py can be used by naming it as a parameter in the test function.
Complete the code to define a fixture in conftest.py that returns a string.
import pytest @pytest.fixture def [1](): return "hello"
Fixtures are defined with @pytest.fixture decorator and a function name used as fixture name.
Fix the error in the fixture usage by completing the test function parameter.
def test_greet([1]): assert [1] == "hello"
The test function must accept the fixture name as parameter to use it.
Fill both blanks to create a fixture that sets up and tears down a resource.
import pytest @pytest.fixture def [1](): resource = open('file.txt', 'w') yield resource [2]
The fixture name is 'file_resource'. The resource must be closed after yield to clean up.
Fill all three blanks to create a test using a fixture and assert its returned value.
def test_value([1]): value = [2] assert value == [3]
The test function uses the fixture 'my_fixture' as parameter. The value is assigned from the fixture and asserted to be 'hello'.