import os
import sys

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

# Use an isolated test database and disable background/side-effect features
os.environ["DATABASE_URL"] = "sqlite:///./test_trading_lab.db"
os.environ["AUTO_SCAN_ENABLED"] = "false"
os.environ["EMAIL_ALERTS_ENABLED"] = "false"
os.environ["ENV"] = "test"
os.environ["REQUIRE_AUTH"] = "false"
os.environ["RATE_LIMIT_PER_MINUTE"] = "0"  # disable limiter in tests
os.environ["DATA_PROVIDER"] = "mock"       # tests never hit live vendors

import pytest


@pytest.fixture(scope="session", autouse=True)
def _cleanup_db():
    yield
    for f in ("test_trading_lab.db",):
        try:
            os.remove(f)
        except OSError:
            pass
