Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to make the fixture run automatically for each test.
PyTest
import pytest @pytest.fixture([1]) def setup_data(): print("Setup data") def test_example(): assert True
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'scope' instead of 'autouse' to run fixture automatically.
Forgetting to set autouse=True so fixture does not run automatically.
✗ Incorrect
The 'autouse=True' parameter makes the fixture run automatically for each test without needing to be explicitly used.
2fill in blank
mediumComplete the code to verify that the autouse fixture runs before the test function.
PyTest
import pytest @pytest.fixture([1]) def setup_env(): print("Environment setup") def test_run(): assert True
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'scope' without autouse does not run fixture automatically.
Not adding any parameter so fixture is not triggered.
✗ Incorrect
Setting autouse=True ensures the fixture runs automatically before the test function.
3fill in blank
hardFix the error in the fixture declaration to make it autouse.
PyTest
import pytest @pytest.fixture(autouse=[1]) def prepare(): print("Preparing") def test_check(): assert True
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'True' as a string instead of boolean True.
Using 1 instead of True which may cause confusion.
✗ Incorrect
The autouse parameter must be a boolean True without quotes to work correctly.
4fill in blank
hardFill both blanks to create an autouse fixture with module scope.
PyTest
import pytest @pytest.fixture([1], [2]) def setup_module(): print("Module setup") def test_one(): assert True
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using scope='function' which runs fixture for each test function.
Setting autouse=False so fixture does not run automatically.
✗ Incorrect
To make a fixture run automatically for all tests in a module, use autouse=True and scope='module'.
5fill in blank
hardFill all three blanks to create an autouse fixture with function scope and a print statement.
PyTest
import pytest @pytest.fixture([1], [2]) def setup_func(): print([3]) def test_sample(): assert True
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong scope like 'module' when function scope is needed.
Not using autouse=True so fixture does not run automatically.
Incorrect print message string.
✗ Incorrect
The fixture runs automatically for each function with autouse=True and scope='function'. The print statement shows the setup message.