0
0
PyTesttesting~10 mins

Custom markers 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 mark the test with a custom marker named 'slow'.

PyTest
import pytest

@pytest.mark.[1]
def test_example():
    assert 1 + 1 == 2
Drag options to blanks, or click blank then click option'
Aslow
Bfast
Cskip
Dparametrize
Attempts:
3 left
💡 Hint
Common Mistakes
Using a built-in marker like 'skip' instead of the custom marker 'slow'.
Forgetting to use '@pytest.mark.' before the marker name.
2fill in blank
medium

Complete the code to run only tests marked with 'database' using pytest command line option.

PyTest
pytest -m [1]
Drag options to blanks, or click blank then click option'
Aslow
Bnetwork
Cskip
Ddatabase
Attempts:
3 left
💡 Hint
Common Mistakes
Using a marker name that does not exist on any test.
Omitting the -m option.
3fill in blank
hard

Fix the error in the code to register a custom marker 'api' in pytest.ini.

PyTest
[pytest]
markers =
    [1]: mark test as API test
Drag options to blanks, or click blank then click option'
Aapi
BAPI
CApi
DapI
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase or mixed case marker names in pytest.ini that don't match the code.
Not registering the marker in pytest.ini causing warnings.
4fill in blank
hard

Fill both blanks to mark a test with 'integration' and skip it conditionally when a variable is False.

PyTest
import pytest

@pytest.mark.[1]
@pytest.mark.skipif(not is_ready, reason='Not ready')
def test_integration():
    assert True
Drag options to blanks, or click blank then click option'
Aintegration
Bunit
Cslow
Dskip
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'skip' instead of 'skipif' for conditional skipping.
Using wrong marker names.
5fill in blank
hard

Fill all three blanks to define and use a custom marker 'performance' with pytest.mark and run only those tests.

PyTest
import pytest

@pytest.mark.[1]
def test_speed():
    assert 100 < 200

# Run tests with: pytest -m [2]

# Register marker in pytest.ini:
#[pytest]
#markers =
#    [3]: mark test as performance test
Drag options to blanks, or click blank then click option'
Aperformance
Dslow
Attempts:
3 left
💡 Hint
Common Mistakes
Using different marker names in code and pytest.ini.
Forgetting to register the marker in pytest.ini.