Framework Mode - Test discovery rules
Folder Structure
project-root/ ├── tests/ │ ├── test_example.py │ ├── test_login.py │ └── subfolder/ │ └── test_subfeature.py ├── src/ │ └── app_code.py ├── pytest.ini └── conftest.py
project-root/ ├── tests/ │ ├── test_example.py │ ├── test_login.py │ └── subfolder/ │ └── test_subfeature.py ├── src/ │ └── app_code.py ├── pytest.ini └── conftest.py
test_ or ending with _test.py inside the tests/ folder or its subfolders.conftest.py files provide shared setup and fixtures for tests.src/ or similar folder, separate from tests.pytest.ini or tox.ini files configure pytest options and discovery rules.Use pytest.ini to control test discovery rules and settings:
[pytest] testpaths = tests python_files = test_*.py *_test.py python_classes = Test* python_functions = test_*
This tells pytest to look for tests only in the tests/ folder, and to recognize test files, classes, and functions by these naming patterns.
Environment variables or command line options can override these settings for different environments or browsers.
--junitxml=report.xml to generate XML reports readable by CI tools.pytest-html for human-friendly HTML reports.test_ prefix or _test.py suffix for automatic discovery.tests/ folder to separate from application code.pytest.ini to explicitly define discovery rules to avoid surprises.conftest.py for shared fixtures and hooks to keep tests clean.pytest --collect-only to verify which tests pytest finds before running them.Question: Where would you add a new test file for the user registration feature so pytest discovers it automatically?
Answer: Inside the tests/ folder, with a filename starting with test_ (e.g., test_registration.py).