Framework Mode - Testpaths configuration
Folder Structure
tests/ ├── unit/ │ ├── test_example1.py │ └── test_example2.py ├── integration/ │ └── test_integration.py ├── e2e/ │ └── test_end_to_end.py ├── __init__.py conftest.py pytest.ini
tests/ ├── unit/ │ ├── test_example1.py │ └── test_example2.py ├── integration/ │ └── test_integration.py ├── e2e/ │ └── test_end_to_end.py ├── __init__.py conftest.py pytest.ini
tests/ by type (unit, integration, e2e).conftest.py for setup and teardown.pytest.ini controls test discovery and testpaths.utils/ folder if needed.Use pytest.ini to specify testpaths to tell pytest where to look for tests.
[pytest] testpaths = tests/unit tests/integration # This limits pytest to only look inside these folders for tests.
Other config options can include markers, addopts, and python_files patterns.
Use conftest.py for shared fixtures and environment setup.
pytest-html or pytest-cov for HTML reports and coverage reports.pytest commands using the pytest.ini config.testpaths in pytest.ini: This speeds up test discovery and avoids running unwanted files.conftest.py clean: Only put shared fixtures and hooks here to avoid confusion.test_ or end with _test.py for pytest to find them easily.Where would you add a new test file for API integration tests in this framework structure?
testpaths setting in a pytest.ini file?testpathstestpaths setting tells pytest where to find test files by listing directories.testpaths.testpaths in pytest.ini to look in folders tests and integration?pytest.ini, testpaths lists folders separated by spaces without quotes or commas.pytest.ini content:[pytest] testpaths = tests integration
project/
tests/
test_alpha.py
integration/
test_beta.py
docs/
test_docs.pytestpaths setting includes tests and integration folders only.test_alpha.py in tests and test_beta.py in integration will be found. test_docs.py is in docs, which is not listed.testpaths = tests in pytest.ini but pytest still discovers tests in other folders. What is the most likely cause?tox.ini or setup.cfg that may override pytest.ini.tests run, likely another config file sets different testpaths or disables it.unit_tests and api_tests folders, but exclude api_tests/slow. How can you configure pytest.ini using testpaths and other settings to achieve this?testpaths = unit_tests api_tests to include both folders.norecursedirs = api_tests/slow to prevent pytest from searching inside that subfolder.ignore which is not a valid pytest.ini setting.Pass the test and this pattern moves unknown