0
0
PyTesttesting~10 mins

Marker registration 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 register a pytest marker named 'slow'.

PyTest
import pytest

def pytest_configure(config):
    config.[1]("slow", description="marks tests as slow")
Drag options to blanks, or click blank then click option'
Aregister_marker
Badd_marker
Caddoption
Dmark
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'register_marker' which is not a valid pytest config method.
Using 'addoption' which is for command line options, not markers.
2fill in blank
medium

Complete the code to mark a test function with the 'slow' marker.

PyTest
import pytest

@pytest.[1]("slow")
def test_example():
    assert True
Drag options to blanks, or click blank then click option'
Aparametrize
Bslow
Cskip
Dmark
Attempts:
3 left
💡 Hint
Common Mistakes
Using '@pytest.slow' which is invalid syntax.
Using '@pytest.parametrize' which is for parameterized tests.
3fill in blank
hard

Fix the error in the pytest marker registration function.

PyTest
def pytest_configure(config):
    config.[1]("slow", description="marks slow tests")
Drag options to blanks, or click blank then click option'
Aadd_marker
Bmark
Caddoption
Dregister_marker
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'register_marker' which is not a valid method.
Using 'addoption' which is unrelated to markers.
4fill in blank
hard

Fill both blanks to register a marker and add a description.

PyTest
def pytest_configure(config):
    config.[1]("performance", description=[2])
Drag options to blanks, or click blank then click option'
Aadd_marker
B"marks tests as performance-related"
C"marks tests for performance"
Dregister_marker
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'register_marker' instead of 'add_marker'.
Not providing a string description.
5fill in blank
hard

Fill all three blanks to register a marker, mark a test, and check the marker in the test.

PyTest
def pytest_configure(config):
    config.[1]("api", description="marks API tests")

import pytest

@pytest.[2]("api")
def test_api_call(request):
    marker = request.node.get_closest_marker([3])
    assert marker is not None
Drag options to blanks, or click blank then click option'
Aadd_marker
Bmark
C"api"
Dslow
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'register_marker' instead of 'add_marker'.
Using wrong marker name in decorator or get_closest_marker.
Passing variable instead of string to get_closest_marker.