Challenge - 5 Problems
Marker Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:30remaining
Purpose of marker registration in pytest
Why is it important to register custom markers in pytest's
pytest.ini or pyproject.toml file?Attempts:
2 left
💡 Hint
Think about what happens if pytest sees a marker it does not recognize.
✗ Incorrect
Registering markers tells pytest about custom labels you use on tests. Without registration, pytest shows warnings and may not allow selecting tests by those markers.
❓ Predict Output
intermediate1:30remaining
Output of pytest when using unregistered marker
What output will pytest produce when running this test with an unregistered marker
@pytest.mark.slow?PyTest
import pytest @pytest.mark.slow def test_example(): assert True
Attempts:
2 left
💡 Hint
Think about pytest's behavior when it sees a marker it does not know.
✗ Incorrect
Pytest runs the test but warns about unknown markers to alert you to possible typos or missing registrations.
❓ locator
advanced1:30remaining
Correct location to register a custom marker
Where should you add the registration for a custom marker named
integration to avoid warnings in pytest?Attempts:
2 left
💡 Hint
Think about pytest configuration files that control test behavior globally.
✗ Incorrect
The
pytest.ini file is the standard place to register markers so pytest knows about them project-wide.❓ assertion
advanced2:00remaining
Assertion to verify marker presence on a test function
Given a test function decorated with
@pytest.mark.api, which assertion correctly checks for the presence of the 'api' marker in a pytest hook?PyTest
def pytest_collection_modifyitems(items): for item in items: # Which assertion is correct here? pass
Attempts:
2 left
💡 Hint
Look at how pytest exposes markers on collected test items.
✗ Incorrect
The
iter_markers() method returns all markers on a test item. Checking their names is the correct way.❓ framework
expert2:00remaining
Effect of missing marker registration on test selection
You have registered a custom marker
db in pytest.ini. You run pytest -m db to select tests with this marker. What happens if you remove the marker registration but still run pytest -m db?Attempts:
2 left
💡 Hint
Consider pytest's behavior when selecting tests by an unregistered marker.
✗ Incorrect
Pytest allows selection by unregistered markers but warns about unknown markers. It runs only matching tests.