Challenge - 5 Problems
pytest Marker Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:30remaining
Purpose of registering markers in pytest.ini
Why is it important to register custom markers in the
pytest.ini file when using pytest?Attempts:
2 left
💡 Hint
Think about what happens if you use a marker that pytest does not recognize.
✗ Incorrect
Registering markers in pytest.ini tells pytest about your custom markers. This prevents warnings and allows you to select tests by marker using command line options.
❓ Predict Output
intermediate2: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
Attempts:
2 left
💡 Hint
Think about pytest's behavior when it sees a marker it does not know.
✗ Incorrect
Pytest shows a warning about unknown markers if they are not registered in pytest.ini but still runs the tests.
❓ locator
advanced1: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?Attempts:
2 left
💡 Hint
Look for the correct syntax for comments in pytest.ini under markers.
✗ Incorrect
The correct syntax uses a colon ':' after the marker name followed by a description. Other separators cause parsing errors or are ignored.
❓ assertion
advanced2: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
Attempts:
2 left
💡 Hint
Think about how pytest exposes ini options in code.
✗ Incorrect
The correct way to check registered markers programmatically is to access pytest.config.getini('markers') which returns a list of registered markers.
❓ framework
expert2: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?Attempts:
2 left
💡 Hint
Consider how pytest handles unknown markers during test selection.
✗ Incorrect
Pytest warns about unknown markers but when filtering with -m for an unregistered marker, it still selects and runs the matching tests.