Challenge - 5 Problems
pytest.ini Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pytest with custom markers in pytest.ini
Given the following pytest.ini configuration and test code, what will be the output when running pytest with the marker filter
-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
The
-m option runs tests matching the given marker.✗ Incorrect
The pytest.ini declares the marker
slow. Running pytest with -m slow runs only tests marked with @pytest.mark.slow. So test_slow runs and passes; test_fast is skipped.❓ assertion
intermediate1:30remaining
Assertion behavior with pytest.ini addopts
If pytest.ini contains
addopts = --maxfail=1 --tb=short, what will happen when two tests fail in a test suite?Attempts:
2 left
💡 Hint
The
--maxfail option limits failures before stopping.✗ Incorrect
The
--maxfail=1 option stops pytest after the first failure. The --tb=short option shows shorter tracebacks. So pytest stops after one failure and shows a short traceback.❓ locator
advanced1:30remaining
Correct pytest.ini section for configuring test paths
Which section header is correct in pytest.ini to specify the directory where pytest should look for tests using
testpaths?Attempts:
2 left
💡 Hint
The official pytest configuration section is
[pytest].✗ Incorrect
The correct section header in pytest.ini is
[pytest]. Other headers like [tool:pytest] are used in other config files but not pytest.ini.🔧 Debug
advanced2:00remaining
Identify the error in pytest.ini configuration
Given this pytest.ini content, what error will pytest raise when running?
PyTest
[pytest]
markers =
slow: marks tests as slow
fast marks tests as fast
Attempts:
2 left
💡 Hint
Check the marker syntax carefully.
✗ Incorrect
The second marker line misses a colon after 'fast'. This causes pytest to raise a ConfigError about invalid marker syntax.
❓ framework
expert2:30remaining
Effect of pytest.ini on test discovery and execution
Consider this pytest.ini:
[pytest]
testpaths = tests
python_files = check_*.py
addopts = -v --disable-warnings
What is the combined effect of these settings when running pytest without arguments?
Attempts:
2 left
💡 Hint
Check each pytest.ini option's effect on discovery and output.
✗ Incorrect
The 'testpaths = tests' limits discovery to the 'tests' directory. 'python_files = check_*.py' limits test files to those matching that pattern. 'addopts = -v --disable-warnings' runs tests verbosely and disables warnings.