"""Pytest configuration: load .env before any tests run."""

import os
from pathlib import Path


def pytest_configure(config):  # pylint: disable=unused-argument
    """Load .env from the repository root into os.environ."""
    env_file = Path(__file__).parent.parent / ".env"
    if not env_file.exists():
        return
    for line in env_file.read_text(encoding="utf-8").splitlines():
        line = line.strip()
        if not line or line.startswith("#") or "=" not in line:
            continue
        key, _, value = line.partition("=")
        key = key.strip()
        value = value.strip()
        if key and key not in os.environ:
            os.environ[key] = value
