Challenge - 5 Problems
Marker Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:30remaining
Purpose of Markers in pytest
What is the main purpose of using markers in pytest for test categorization?
Attempts:
2 left
💡 Hint
Think about how you can run only some tests and skip others easily.
✗ Incorrect
Markers help label tests so you can run only tests with certain labels, making test runs faster and more focused.
❓ Predict Output
intermediate2:00remaining
Output of pytest marker usage
Given the following pytest code, what will be the output when running `pytest -m smoke`?
Selenium Python
import pytest @pytest.mark.smoke def test_login(): assert True @pytest.mark.regression def test_logout(): assert True @pytest.mark.smoke def test_search(): assert True
Attempts:
2 left
💡 Hint
The -m option runs tests with the given marker only.
✗ Incorrect
Using `pytest -m smoke` runs only tests marked with @pytest.mark.smoke, so test_login and test_search run and pass.
❓ assertion
advanced2:00remaining
Correct assertion for marker presence
Which assertion correctly checks if a test function has the marker 'regression' in pytest?
Selenium Python
def test_example(request): # How to assert 'regression' marker is present on this test? pass
Attempts:
2 left
💡 Hint
Use the pytest API to get markers safely.
✗ Incorrect
The get_closest_marker method returns the marker object or None if not found, so checking for not None confirms presence.
🔧 Debug
advanced2:00remaining
Fix marker registration error
You get this error when running pytest: "PytestUnknownMarkWarning: Unknown pytest.mark.regression - is this a typo?". What is the cause?
Attempts:
2 left
💡 Hint
Check your pytest configuration files for marker declarations.
✗ Incorrect
Pytest requires custom markers to be registered in configuration files to avoid warnings.
❓ framework
expert2:30remaining
Combining markers and fixtures for selective setup
You want to run a setup fixture only for tests marked with 'db'. Which pytest feature allows this selective fixture application?
Attempts:
2 left
💡 Hint
Think about how to run fixture code conditionally without decorating every test.
✗ Incorrect
Setting autouse=True runs fixture for all tests, but inside fixture you can check if marker is present and skip setup if not.