Challenge - 5 Problems
Marker Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pytest run with marker filter
Given the following pytest test file, what tests will run when executing
pytest -m "slow"?PyTest
import pytest @pytest.mark.slow def test_a(): assert True @pytest.mark.fast def test_b(): assert True def test_c(): assert True
Attempts:
2 left
💡 Hint
The -m option runs tests matching the given marker expression.
✗ Incorrect
The command
pytest -m "slow" runs only tests marked with @pytest.mark.slow. Here, only test_a has that marker.❓ assertion
intermediate2:00remaining
Correct assertion for marker presence in pytest
Which assertion correctly checks that a test function is marked with the marker 'database' in pytest?
PyTest
import pytest @pytest.mark.database def test_query(): pass
Attempts:
2 left
💡 Hint
pytest stores markers as objects in the pytestmark attribute list.
✗ Incorrect
pytest marks are stored as objects in the list test_query.pytestmark. We must check if any marker's name equals 'database'.
🔧 Debug
advanced2:00remaining
Why does pytest -m 'api and not slow' run no tests?
Given these tests:
import pytest
@pytest.mark.api
@pytest.mark.slow
def test_api_slow():
pass
@pytest.mark.api
def test_api_fast():
pass
@pytest.mark.slow
def test_slow():
pass
Why does pytest -m "api and not slow" run no tests?Attempts:
2 left
💡 Hint
Check pytest documentation for valid marker expression operators.
✗ Incorrect
pytest marker expressions support 'and', 'or', but not 'not'. Using 'not' causes no tests to run.
❓ framework
advanced2:00remaining
How to run tests marked 'ui' or 'integration' but not 'slow' in pytest
Which pytest command runs tests marked with 'ui' or 'integration' but excludes those marked 'slow'?
Attempts:
2 left
💡 Hint
Remember operator precedence and valid operators in pytest marker expressions.
✗ Incorrect
pytest supports 'and' and 'or' but not 'not'. The correct expression is without parentheses and uses 'and' and 'or'.
🧠 Conceptual
expert2:00remaining
Understanding pytest marker expression evaluation order
In pytest marker expressions, which operator has higher precedence?
Attempts:
2 left
💡 Hint
Think about how logical operators usually work in programming languages.
✗ Incorrect
In pytest marker expressions, 'and' has higher precedence than 'or', similar to Python logical operators.