import os
import shutil
import tempfile
from pathlib import Path

# Set isolated paths before any app module is imported by the test files. This
# prevents pytest from touching a real deployment database or session storage.
_TEST_ROOT = Path(tempfile.mkdtemp(prefix='instagram_bot_tests_'))
os.environ['INSTABOT_STORAGE_DIR'] = str(_TEST_ROOT / 'storage')
os.environ['INSTABOT_UPLOAD_DIR'] = str(_TEST_ROOT / 'uploads')


def pytest_sessionfinish(session, exitstatus):
    shutil.rmtree(_TEST_ROOT, ignore_errors=True)
