|
|
3 месяцев назад | |
|---|---|---|
| .. | ||
| e2e | 3 месяцев назад | |
| fixtures | 3 месяцев назад | |
| integration | 3 месяцев назад | |
| logs | 3 месяцев назад | |
| unit | 3 месяцев назад | |
| README.md | 3 месяцев назад | |
| TESTING_FRAMEWORK_VERIFICATION.md | 3 месяцев назад | |
| __init__.py | 3 месяцев назад | |
| conftest.py | 3 месяцев назад | |
| test_framework_setup.py | 3 месяцев назад | |
This directory contains the comprehensive test suite for the RAG System refactoring project.
tests/
├── unit/ # Unit tests for individual components
│ ├── domain/ # Domain layer tests
│ ├── application/ # Application layer tests
│ └── infrastructure/ # Infrastructure layer tests
├── integration/ # Integration tests for component interactions
│ ├── api/ # API integration tests
│ └── database/ # Database integration tests
├── e2e/ # End-to-end tests for complete workflows
├── fixtures/ # Test data and fixtures
│ └── documents/ # Sample documents for testing
├── logs/ # Test execution logs
├── conftest.py # Global pytest configuration and fixtures
└── README.md # This file
pytest
# Unit tests only
pytest -m unit
# Integration tests only
pytest -m integration
# End-to-end tests only
pytest -m e2e
# Run tests in a specific directory
pytest tests/unit/
pytest tests/integration/
pytest tests/e2e/
# Generate coverage report
pytest --cov=src --cov-report=html --cov-report=term
# View HTML coverage report
# Open htmlcov/index.html in your browser
# Generate XML coverage report (for CI/CD)
pytest --cov=src --cov-report=xml
# Run all property tests
pytest -m property
# Run property tests with verbose output
pytest -m property -v
# Run property tests with more examples
pytest -m property --hypothesis-show-statistics
# Minimal output
pytest -q
# Verbose output
pytest -v
# Very verbose output (show test names and results)
pytest -vv
# Run a specific test file
pytest tests/unit/domain/test_entities.py
# Run a specific test class
pytest tests/unit/domain/test_entities.py::TestDocument
# Run a specific test method
pytest tests/unit/domain/test_entities.py::TestDocument::test_update_content
# Run only slow tests
pytest -m slow
# Run tests that don't require database
pytest -m "not requires_db"
# Run unit tests that don't require external services
pytest -m "unit and not requires_external_service"
# Install pytest-xdist first: pip install pytest-xdist
pytest -n auto
# Install pytest-timeout first: pip install pytest-timeout
pytest --timeout=300
The following markers are available for categorizing tests:
@pytest.mark.unit - Unit tests (automatically added for tests in unit/)@pytest.mark.integration - Integration tests (automatically added for tests in integration/)@pytest.mark.e2e - End-to-end tests (automatically added for tests in e2e/)@pytest.mark.slow - Tests that take > 1 second@pytest.mark.requires_db - Tests requiring database connection@pytest.mark.requires_vector_db - Tests requiring vector database connection@pytest.mark.requires_external_service - Tests requiring external services@pytest.mark.property - Property-based tests using Hypothesis# tests/unit/domain/test_entities.py
import pytest
from domain.vector_search.entities import Document
class TestDocument:
"""Document entity unit tests"""
def test_update_content_changes_content(self):
"""Test that updating content changes the document content"""
# Arrange
doc = Document(id="1", content="original", ...)
# Act
doc.update_content("new content")
# Assert
assert doc.content == "new content"
# tests/integration/infrastructure/test_repositories.py
import pytest
@pytest.mark.integration
@pytest.mark.requires_db
class TestDocumentRepository:
"""Document repository integration tests"""
async def test_save_and_find(self, test_db_session):
"""Test saving and finding a document"""
# Test implementation
pass
# tests/unit/domain/test_properties.py
from hypothesis import given, strategies as st
import pytest
class TestVectorProperties:
"""Vector property-based tests"""
@pytest.mark.property
@given(st.lists(st.floats(allow_nan=False), min_size=1))
def test_vector_dimension_count(self, dimensions):
"""Property: Vector dimension count equals list length"""
vector = Vector(dimensions)
assert vector.dimension_count == len(dimensions)
# tests/e2e/test_document_workflow.py
import pytest
from httpx import AsyncClient
@pytest.mark.e2e
class TestDocumentWorkflow:
"""Document workflow end-to-end tests"""
async def test_complete_lifecycle(self, client):
"""Test complete document lifecycle"""
# Create -> Search -> Update -> Delete
pass
Global fixtures are defined in conftest.py:
event_loop - Async event loop for async testsreset_singletons - Resets singleton instances between teststest_data_dir - Path to test data directorysample_documents_dir - Path to sample documentsmock_settings - Mock configuration settingstest_db_session - Test database session (to be implemented)mock_vector_db - Mock vector database (to be implemented)mock_embedding_service - Mock embedding service (to be implemented)Tests are automatically run in CI/CD pipeline on:
See .github/workflows/test.yml for CI configuration.
Make sure you have installed all dependencies:
pip install -r requirements.txt
pip install pytest pytest-asyncio pytest-cov hypothesis httpx
Make sure pytest-asyncio is installed and asyncio_mode = auto is set in pytest.ini.
Run pytest with coverage flags:
pytest --cov=src --cov-report=html
Run tests in parallel:
pip install pytest-xdist
pytest -n auto