Challenge - 5 Problems
setup.cfg pytest Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pytest with setup.cfg markers
Given the following
setup.cfg configuration and test file, what will be the output when running pytest without any additional options?PyTest
[pytest]
markers =
slow: marks tests as slow
# test_sample.py
import pytest
@pytest.mark.slow
def test_slow():
assert True
def test_fast():
assert TrueAttempts:
2 left
💡 Hint
Markers declared in setup.cfg do not skip tests by default.
✗ Incorrect
Declaring markers in setup.cfg only registers them to avoid warnings. Tests marked with 'slow' still run unless explicitly filtered or skipped.
❓ assertion
intermediate2:00remaining
Correct assertion for test selection by keyword
With this
setup.cfg snippet, which assertion correctly verifies that only tests marked with 'slow' run when using pytest -m slow?PyTest
[pytest]
markers =
slow: marks tests as slow
# test_sample.py
import pytest
@pytest.mark.slow
def test_slow():
assert True
def test_fast():
assert TrueAttempts:
2 left
💡 Hint
Using
-m slow runs only tests with the slow marker.✗ Incorrect
The command
pytest -m slow runs only tests marked 'slow', so output should show test_slow but not test_fast.🔧 Debug
advanced2:00remaining
Why does pytest warn about unknown marker despite setup.cfg?
You have this
setup.cfg:
[pytest]
markers =
regression: marks regression tests
But running tests marked with @pytest.mark.regression still shows a warning about unknown marker. What is the most likely cause?Attempts:
2 left
💡 Hint
pytest reads setup.cfg only if it is in the current directory or above.
✗ Incorrect
If setup.cfg is not in the directory pytest runs from or above, pytest won't find the marker declarations and warns about unknown markers.
❓ framework
advanced2:00remaining
Configuring pytest to ignore warnings via setup.cfg
Which
setup.cfg snippet correctly configures pytest to ignore DeprecationWarning during test runs?Attempts:
2 left
💡 Hint
pytest uses filterwarnings option with ignore action.
✗ Incorrect
The correct syntax is 'filterwarnings = ignore::DeprecationWarning' to suppress those warnings.
🧠 Conceptual
expert3:00remaining
Effect of testpaths in setup.cfg on test discovery
Given this
setup.cfg:
[pytest]
testpaths = tests integration
What is the effect of this configuration when running pytest without arguments?Attempts:
2 left
💡 Hint
testpaths limits where pytest looks for tests.
✗ Incorrect
The testpaths option tells pytest to look only in the specified directories for tests.