Files
AegisGitea-MCP/tests/conftest.py
2026-01-31 15:55:22 +00:00

43 lines
1.3 KiB
Python

"""Pytest configuration and fixtures."""
import os
import tempfile
from pathlib import Path
from typing import Generator
import pytest
from aegis_gitea_mcp.audit import reset_audit_logger
from aegis_gitea_mcp.auth import reset_validator
from aegis_gitea_mcp.config import reset_settings
@pytest.fixture(autouse=True)
def reset_globals(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Generator[None, None, None]:
"""Reset global singletons between tests and set up temp audit log."""
# Reset singletons before each test to ensure clean state
reset_settings()
reset_audit_logger()
reset_validator()
# Use temporary directory for audit logs in tests
audit_log_path = tmp_path / "audit.log"
monkeypatch.setenv("AUDIT_LOG_PATH", str(audit_log_path))
yield
# Also reset after test for cleanup
reset_settings()
reset_audit_logger()
reset_validator()
@pytest.fixture
def mock_env(monkeypatch: pytest.MonkeyPatch) -> None:
"""Set up mock environment variables for testing."""
monkeypatch.setenv("GITEA_URL", "https://gitea.example.com")
monkeypatch.setenv("GITEA_TOKEN", "test-token-12345")
monkeypatch.setenv("MCP_HOST", "0.0.0.0")
monkeypatch.setenv("MCP_PORT", "8080")
monkeypatch.setenv("LOG_LEVEL", "DEBUG")