import os
import pytest
from oaa.settings import config as _config


def pytest_configure(config):
    config.addinivalue_line(
        "markers", "requires_db: tests that require database connection (DB_PASSWORD)"
    )


def pytest_collection_modifyitems(config, items):
    skip_db = pytest.mark.skip(
        reason="requires database connection (DB_PASSWORD environment variable)"
    )

    db_password = os.environ.get("DB_PASSWORD")

    for item in items:
        if "oracle" in item.nodeid.lower() or "sqlplus" in item.nodeid.lower():
            if not db_password:
                item.add_marker(skip_db)


@pytest.fixture
def config():
    _config.update()
    yield _config
    _config.reset()
