Overview - Testpaths configuration
What is it?
Testpaths configuration in pytest is a way to tell pytest where to look for test files when running tests. Instead of searching the entire project, you can specify certain folders or paths to focus on. This helps pytest find tests faster and avoid running unwanted files. It is set in the pytest configuration file, usually named pytest.ini.
Why it matters
Without testpaths configuration, pytest searches the whole project directory for tests, which can slow down test runs and include irrelevant files. This wastes time and can cause confusion if non-test files are accidentally run. By configuring testpaths, you control test discovery, making testing faster and more reliable, especially in large projects.
Where it fits
Before learning testpaths, you should understand basic pytest test discovery and how pytest finds and runs tests. After mastering testpaths, you can explore other pytest configuration options like markers, addopts, and test selection strategies to further customize test runs.