0
0
PyTesttesting~20 mins

pytest.ini configuration - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
pytest.ini Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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 True
AOnly <code>test_slow</code> runs and passes; <code>test_fast</code> is skipped.
BBoth <code>test_slow</code> and <code>test_fast</code> run and pass.
COnly <code>test_fast</code> runs and passes; <code>test_slow</code> is skipped.
DNo tests run because marker <code>slow</code> is not recognized.
Attempts:
2 left
💡 Hint
The -m option runs tests matching the given marker.
assertion
intermediate
1: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?
APytest stops after the first failure but shows full tracebacks.
BPytest runs all tests and shows full tracebacks for failures.
CPytest runs all tests and shows short tracebacks.
DPytest stops after the first failure and shows a short traceback.
Attempts:
2 left
💡 Hint
The --maxfail option limits failures before stopping.
locator
advanced
1: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?
A
[pytest]
testpaths = tests
B
[pytest.ini]
testpaths = tests
C
[config]
testpaths = tests
D
[tool:pytest]
testpaths = tests
Attempts:
2 left
💡 Hint
The official pytest configuration section is [pytest].
🔧 Debug
advanced
2: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
Apytest ignores the invalid marker and runs all tests normally.
Bpytest raises a ConfigError due to missing colon in marker declaration.
Cpytest raises a SyntaxError parsing pytest.ini.
Dpytest runs but warns about unknown marker 'fast'.
Attempts:
2 left
💡 Hint
Check the marker syntax carefully.
framework
expert
2: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?
APytest looks only in the 'tests' folder for all test files, runs tests quietly, and suppresses warnings.
BPytest looks in all folders for files starting with 'check_' and ending with '.py', runs tests verbosely, and shows warnings.
CPytest looks only in the 'tests' folder for files starting with 'check_' and ending with '.py', runs tests verbosely, and suppresses warnings.
DPytest looks in all folders for all test files, runs tests quietly, and shows warnings.
Attempts:
2 left
💡 Hint
Check each pytest.ini option's effect on discovery and output.