Framework Mode - Conftest.py purpose
Folder Structure of a Pytest Framework
project-root/ ├── tests/ │ ├── test_login.py │ ├── test_checkout.py │ └── conftest.py ├── src/ │ └── app_code.py ├── requirements.txt └── pytest.ini
project-root/ ├── tests/ │ ├── test_login.py │ ├── test_checkout.py │ └── conftest.py ├── src/ │ └── app_code.py ├── requirements.txt └── pytest.ini
tests/ folder, e.g., test_login.py.src/ or similar.pytest.ini to configure pytest behavior.conftest.py is used to define fixtures that can be shared across multiple test files without importing them explicitly. It helps manage:
Example snippet inside conftest.py:
import pytest
@pytest.fixture(scope="session")
def browser():
print("Setup browser")
yield "ChromeDriver"
print("Teardown browser")
Pytest integrates easily with reporting tools and CI/CD pipelines:
pytest --junitxml=report.xml to generate XML reports readable by CI tools.pytest-html create human-friendly HTML reports.conftest.py can include hooks to customize reporting or logging.conftest.py to avoid repetitive code in tests.function, module, session) to optimize setup time.conftest.py manually; pytest discovers it automatically.conftest.py files in subfolders for modular fixture management.Where in this folder structure would you add a new fixture to initialize a database connection for all tests?