Files
HCFS/hcfs-python/tests/conftest.py
2025-07-30 09:34:16 +10:00

57 lines
1.9 KiB
Python

"""
Pytest configuration and shared fixtures for HCFS test suite.
"""
import pytest
import tempfile
import shutil
from pathlib import Path
import sys
# Add the project root to Python path
sys.path.insert(0, str(Path(__file__).parent.parent))
@pytest.fixture(scope="session")
def temp_test_dir():
"""Create a temporary directory for all tests in the session."""
temp_dir = Path(tempfile.mkdtemp(prefix="hcfs_test_"))
yield temp_dir
shutil.rmtree(temp_dir, ignore_errors=True)
@pytest.fixture
def temp_db_path(temp_test_dir):
"""Create a temporary database path."""
return str(temp_test_dir / f"test_{pytest.current_item.name}.db")
@pytest.fixture
def temp_vector_path(temp_test_dir):
"""Create a temporary vector database path."""
return str(temp_test_dir / f"test_vectors_{pytest.current_item.name}.db")
# Configure pytest markers
def pytest_configure(config):
"""Configure custom pytest markers."""
config.addinivalue_line(
"markers", "slow: marks tests as slow (deselect with '-m \"not slow\"')"
)
config.addinivalue_line(
"markers", "integration: marks tests as integration tests"
)
config.addinivalue_line(
"markers", "unit: marks tests as unit tests"
)
# Custom pytest collection hook
def pytest_collection_modifyitems(config, items):
"""Modify test collection to add markers based on test file names."""
for item in items:
# Mark integration tests
if "test_integration" in item.fspath.basename:
item.add_marker(pytest.mark.integration)
# Mark unit tests
elif any(name in item.fspath.basename for name in ["test_context_db", "test_embeddings"]):
item.add_marker(pytest.mark.unit)
# Mark slow tests based on test name patterns
if any(pattern in item.name for pattern in ["large_scale", "performance", "concurrent", "load"]):
item.add_marker(pytest.mark.slow)