"""
Pytest configuration for mainline.
"""

import pytest


def pytest_configure(config):
    """Configure pytest to skip integration tests by default."""
    config.addinivalue_line(
        "markers",
        "integration: marks tests as integration tests (require external services)",
    )
    config.addinivalue_line("markers", "ntfy: marks tests that require ntfy service")


def pytest_collection_modifyitems(config, items):
    """Skip integration/e2e tests unless explicitly requested with -m."""
    # Get the current marker expression
    marker_expr = config.getoption("-m", default="")

    # If explicitly running integration or e2e, don't skip them
    if marker_expr in ("integration", "e2e", "integration or e2e"):
        return

    # Skip integration tests
    skip_integration = pytest.mark.skip(reason="need -m integration to run")
    for item in items:
        if "integration" in item.keywords:
            item.add_marker(skip_integration)

    # Skip e2e tests by default (they require browser/display)
    skip_e2e = pytest.mark.skip(reason="need -m e2e to run")
    for item in items:
        if "e2e" in item.keywords and "integration" not in item.keywords:
            item.add_marker(skip_e2e)
