conftest.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # -*- coding: utf-8 -*-
  2. """
  3. Pytest-Konfiguration und gemeinsame Fixtures.
  4. """
  5. import asyncio
  6. import sys
  7. import tempfile
  8. from pathlib import Path
  9. from typing import Generator, AsyncGenerator
  10. import pytest
  11. # Projekt-Pfad hinzufügen
  12. sys.path.insert(0, str(Path(__file__).parent.parent))
  13. @pytest.fixture(scope="session")
  14. def event_loop():
  15. """Erstellt einen Event-Loop für die gesamte Test-Session."""
  16. loop = asyncio.new_event_loop()
  17. yield loop
  18. loop.close()
  19. @pytest.fixture
  20. def temp_dir() -> Generator[Path, None, None]:
  21. """Erstellt ein temporäres Verzeichnis für Tests."""
  22. with tempfile.TemporaryDirectory() as tmpdir:
  23. yield Path(tmpdir)
  24. @pytest.fixture
  25. def temp_config_file(temp_dir: Path) -> Path:
  26. """Erstellt eine temporäre Konfigurationsdatei."""
  27. config_path = temp_dir / "test_config.json"
  28. config_path.write_text('{"test": "value", "number": 42}')
  29. return config_path
  30. @pytest.fixture
  31. def sample_audio_data() -> bytes:
  32. """Erstellt Beispiel-Audiodaten."""
  33. # 1 Sekunde Stille bei 16kHz, 16-bit mono
  34. return b"\x00\x00" * 16000