"""Pytest fixtures for telegram-bot tests.""" import sys import tempfile from pathlib import Path import pytest # Add the app directory to path so `import db` works when running pytest sys.path.insert(0, str(Path(__file__).parent.parent)) @pytest.fixture(autouse=True) def fresh_db(monkeypatch): """Replace DB_PATH with a temp file before any test runs.""" import db as _db tmp = tempfile.NamedTemporaryFile(suffix=".db", delete=False) tmp_path = Path(tmp.name) tmp.close() monkeypatch.setattr(_db, "DB_PATH", tmp_path) _db.init_db() yield tmp_path tmp_path.unlink(missing_ok=True)