Spaces:
Running
Running
File size: 1,893 Bytes
016b413 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
"""Shared pytest fixtures for all tests."""
from unittest.mock import AsyncMock
import pytest
from src.utils.models import Citation, Evidence
@pytest.fixture
def mock_httpx_client(mocker):
"""Mock httpx.AsyncClient for API tests."""
mock = mocker.patch("httpx.AsyncClient")
mock.return_value.__aenter__ = AsyncMock(return_value=mock.return_value)
mock.return_value.__aexit__ = AsyncMock(return_value=None)
return mock
@pytest.fixture
def mock_llm_response():
"""Factory fixture for mocking LLM responses."""
def _mock(content: str):
return AsyncMock(return_value=content)
return _mock
@pytest.fixture
def sample_evidence():
"""Sample Evidence objects for testing."""
return [
Evidence(
content="Metformin shows neuroprotective properties in Alzheimer's models...",
citation=Citation(
source="pubmed",
title="Metformin and Alzheimer's Disease: A Systematic Review",
url="https://pubmed.ncbi.nlm.nih.gov/12345678/",
date="2024-01-15",
authors=["Smith J", "Johnson M"],
),
relevance=0.85,
),
Evidence(
content="Drug repurposing offers faster path to treatment...",
citation=Citation(
source="pubmed",
title="Drug Repurposing Strategies",
url="https://example.com/drug-repurposing",
date="Unknown",
authors=[],
),
relevance=0.72,
),
]
# Global timeout for integration tests to prevent hanging
@pytest.fixture(scope="session", autouse=True)
def integration_test_timeout():
"""Set default timeout for integration tests."""
# This fixture runs automatically for all tests
# Individual tests can override with asyncio.wait_for
pass
|