0
0
PyTesttesting~10 mins

Conftest.py purpose in PyTest - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to use a pytest fixture from conftest.py.

PyTest
def test_example([1]):
    assert 1 + 1 == 2
Drag options to blanks, or click blank then click option'
Asetup
Bmy_fixture
Cconftest
Dpytest
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to import fixture manually instead of using it as a parameter
Using a wrong fixture name
2fill in blank
medium

Complete the code to define a fixture in conftest.py that returns a string.

PyTest
import pytest

@pytest.fixture

def [1]():
    return "hello"
Drag options to blanks, or click blank then click option'
Amy_fixture
Bsetup
Cconftest
Dtest_func
Attempts:
3 left
💡 Hint
Common Mistakes
Not using @pytest.fixture decorator
Using invalid function names
3fill in blank
hard

Fix the error in the fixture usage by completing the test function parameter.

PyTest
def test_greet([1]):
    assert [1] == "hello"
Drag options to blanks, or click blank then click option'
Asetup
Bgreet
Cmy_fixture
Dfixture
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name different from fixture name
Not passing fixture as parameter
4fill in blank
hard

Fill both blanks to create a fixture that sets up and tears down a resource.

PyTest
import pytest

@pytest.fixture

def [1]():
    resource = open('file.txt', 'w')
    yield resource
    [2]
Drag options to blanks, or click blank then click option'
Afile_resource
Bresource.close()
Cclose()
Dfile.close()
Attempts:
3 left
💡 Hint
Common Mistakes
Not closing the resource after yield
Using wrong variable name to close
5fill in blank
hard

Fill all three blanks to create a test using a fixture and assert its returned value.

PyTest
def test_value([1]):
    value = [2]
    assert value == [3]
Drag options to blanks, or click blank then click option'
Amy_fixture
C"hello"
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Not using fixture as parameter
Assigning value incorrectly
Wrong assertion value