Challenge - 5 Problems
Testpaths Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of pytest testpaths effect
Given the pytest configuration below, what tests will pytest discover and run?
PyTest
[pytest] testpaths = tests/integration # Directory structure: # tests/ # ├── integration/ # │ └── test_api.py # └── unit/ # └── test_utils.py # Both test_api.py and test_utils.py contain valid test functions.
Attempts:
2 left
💡 Hint
The testpaths setting limits pytest to look only inside specified directories.
✗ Incorrect
The testpaths option tells pytest to only look for tests inside the specified directory 'tests/integration'. Therefore, tests in 'tests/unit' are ignored.
❓ assertion
intermediate2:00remaining
Assertion to verify testpaths filtering
You want to write a pytest test that verifies pytest only collects tests from the 'tests/functional' directory as set in testpaths. Which assertion correctly checks this behavior?
PyTest
import pytest collected = pytest.main(['--collect-only']) # Assume collected_tests is a list of test node ids collected by pytest
Attempts:
2 left
💡 Hint
To confirm filtering, all collected tests should be inside the specified directory.
✗ Incorrect
Using all() ensures every collected test path includes 'tests/functional', confirming pytest only collected tests from that directory.
🔧 Debug
advanced2:00remaining
Why are tests outside testpaths not running?
You configured pytest with testpaths = ['tests/api'] but tests in 'tests/api' and 'tests/db' exist. Only tests in 'tests/api' run. You want tests in both directories to run. What is the cause?
PyTest
[pytest] testpaths = tests/api
Attempts:
2 left
💡 Hint
Check how testpaths limits test discovery.
✗ Incorrect
The testpaths option limits pytest to only look inside the specified directories. Since 'tests/db' is not listed, its tests are not discovered or run.
❓ framework
advanced2:00remaining
Configuring multiple testpaths in pytest.ini
How should you correctly configure pytest.ini to include both 'tests/unit' and 'tests/integration' directories in testpaths?
Attempts:
2 left
💡 Hint
Check pytest.ini syntax for multi-line values.
✗ Incorrect
pytest.ini supports multi-line values for options. Listing each directory on its own indented line under testpaths is the correct way to specify multiple paths.
🧠 Conceptual
expert2:00remaining
Effect of testpaths on pytest test collection order
Which statement about the effect of the testpaths configuration on pytest test collection order is true?
Attempts:
2 left
💡 Hint
Consider what testpaths controls versus test order.
✗ Incorrect
testpaths limits where pytest looks for tests but does not control the order of test collection or execution. Test order is controlled by other pytest options or plugins.