Challenge - 5 Problems
Pytest Configuration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pytest with custom testpaths in pyproject.toml
Given this
pyproject.toml configuration, what will pytest discover and run?PyTest
[tool.pytest.ini_options] testpaths = ["tests/integration", "tests/unit"]
Attempts:
2 left
💡 Hint
The
testpaths option limits where pytest looks for tests.✗ Incorrect
The testpaths setting in pyproject.toml tells pytest to only look for tests inside the specified folders. Here, only 'tests/integration' and 'tests/unit' are included.
❓ assertion
intermediate2:00remaining
Correct assertion for pytest capturing output
You want to check that your function prints 'Hello World' when run. Which pytest assertion correctly tests this using
capsys?PyTest
def greet(): print("Hello World") def test_greet(capsys): greet() captured = capsys.readouterr() # Which assertion below is correct?
Attempts:
2 left
💡 Hint
Remember print adds a newline character at the end.
✗ Incorrect
When using capsys, captured.out contains stdout including newlines. The print function adds a newline, so the output ends with '\n'.
❓ locator
advanced2:00remaining
Identify the correct pytest marker configuration in pyproject.toml
Which
pyproject.toml snippet correctly registers a custom marker named 'slow' with a description?Attempts:
2 left
💡 Hint
Markers must be a list of strings with 'name: description' format.
✗ Incorrect
The markers option expects a list of strings, each string describing a marker name and its purpose separated by a colon.
🔧 Debug
advanced2:00remaining
Why does pytest ignore tests in a subfolder despite pyproject.toml settings?
You set
testpaths = ["tests"] in pyproject.toml, but pytest does not find tests in tests/api. What is the most likely cause?Attempts:
2 left
💡 Hint
Pytest discovers tests by file name patterns by default.
✗ Incorrect
Pytest looks for test files matching patterns like 'test_*.py' or '*_test.py'. If files in 'tests/api' do not follow this, pytest ignores them even if the folder is included.
❓ framework
expert2:00remaining
Effect of adding 'addopts' in pyproject.toml on pytest runs
Given this
pyproject.toml snippet, what is the effect of the addopts option when running pytest?PyTest
[tool.pytest.ini_options]
addopts = "-v --maxfail=2"
Attempts:
2 left
💡 Hint
The
--maxfail option limits how many failures stop the test run.✗ Incorrect
The addopts option adds command-line arguments to every pytest run. Here, -v enables verbose output, and --maxfail=2 stops testing after two failures.