0
0
PyTesttesting~10 mins

Fixture dependencies (fixture using fixture) 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 define a fixture named db.

PyTest
import pytest

@pytest.fixture
 def [1]():
    return "database connection"
Drag options to blanks, or click blank then click option'
Aconn
Bclient
Cdb
Dsetup
Attempts:
3 left
💡 Hint
Common Mistakes
Using a fixture name that does not match the resource purpose.
Forgetting the @pytest.fixture decorator.
2fill in blank
medium

Complete the code to make the user fixture depend on the db fixture.

PyTest
import pytest

@pytest.fixture
def db():
    return "database connection"

@pytest.fixture
def user([1]):
    return f"user using {db}"
Drag options to blanks, or click blank then click option'
Aclient
Bdb
Cconnection
Dsetup
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong parameter name that does not match any fixture.
Not including the dependency fixture as a parameter.
3fill in blank
hard

Fix the error in the test function to use the user fixture correctly.

PyTest
def test_user_access([1]):
    assert user == "user using database connection"
Drag options to blanks, or click blank then click option'
Auser
Bclient
Cdb
Dconnection
Attempts:
3 left
💡 Hint
Common Mistakes
Using a fixture name not defined or not passed as parameter.
Trying to access fixture variables without declaring them as parameters.
4fill in blank
hard

Fill both blanks to create a fixture session that depends on db and returns a session string.

PyTest
@pytest.fixture
def session([1]):
    return f"session with [2]"
Drag options to blanks, or click blank then click option'
Adb
Bclient
Dconnection
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the parameter and the string interpolation.
Forgetting to include the dependency fixture as a parameter.
5fill in blank
hard

Fill all three blanks to define a test that uses the session fixture and asserts its value.

PyTest
def test_session_value([1]):
    expected = "session with [2]"
    assert [3] == expected
Drag options to blanks, or click blank then click option'
Asession
Bdatabase connection
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong fixture names in parameters or assertions.
Mismatching expected string and actual fixture value.