0
0
PyTesttesting~20 mins

Registering markers in pytest.ini - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
pytest Marker Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Purpose of registering markers in pytest.ini
Why is it important to register custom markers in the pytest.ini file when using pytest?
ATo automatically run all tests without specifying any marker
BTo disable all tests that do not have a marker
CTo avoid warnings about unknown markers and enable filtering tests by those markers
DTo change the default test discovery pattern
Attempts:
2 left
💡 Hint
Think about what happens if you use a marker that pytest does not recognize.
Predict Output
intermediate
2:00remaining
Output when using unregistered marker
What warning or error will pytest show when running tests with an unregistered custom marker?
PyTest
[test_sample.py]
import pytest

@pytest.mark.slow
def test_example():
    assert True

# pytest.ini does NOT register 'slow' marker
AWARNING: Unknown pytest.mark.slow - is this a typo? You can register markers in pytest.ini
BERROR: Marker 'slow' not found. Test run aborted.
CNo warnings or errors, test runs normally
DSyntaxError: invalid marker usage
Attempts:
2 left
💡 Hint
Think about pytest's behavior when it sees a marker it does not know.
locator
advanced
1:30remaining
Correct pytest.ini marker registration syntax
Which of the following is the correct way to register a custom marker named database in pytest.ini?
A
[pytest]
markers = database; mark tests that require database access
B
[pytest]
markers = database - mark tests that require database access
C
[pytest]
markers = database # mark tests that require database access
D
[pytest]
markers = database: mark tests that require database access
Attempts:
2 left
💡 Hint
Look for the correct syntax for comments in pytest.ini under markers.
assertion
advanced
2:00remaining
Assertion to check marker registration effect
Given the following pytest.ini and test code, which assertion correctly verifies that the api marker is registered and can be used to select tests?
PyTest
[pytest.ini]
[pytest]
markers = api: mark tests as API tests

[test_api.py]
import pytest

@pytest.mark.api
def test_api_call():
    assert True
Aassert 'api' in pytest.markers
Bassert any(m.startswith('api:') for m in pytest.config.getini('markers'))
Cassert 'api' in pytest.ini
Dassert pytest.mark.api is not None
Attempts:
2 left
💡 Hint
Think about how pytest exposes ini options in code.
framework
expert
2:30remaining
Effect of missing marker registration on test selection
If a custom marker integration is used in tests but NOT registered in pytest.ini, what happens when you run pytest -m integration?
APytest shows a warning about unknown marker but runs tests with the integration marker
BPytest runs all tests ignoring the marker filter
CPytest raises an error and aborts the test run
DPytest runs only tests with the integration marker without warnings
Attempts:
2 left
💡 Hint
Consider how pytest handles unknown markers during test selection.