feat(setup): T05 configure pytest with coverage
- Create pytest.ini with: - Test discovery configuration (testpaths, python_files) - Asyncio mode settings - Coverage configuration (>=90% requirement) - Custom markers (unit, integration, e2e, slow) - Update conftest.py with: - pytest_asyncio plugin - Shared fixtures (project_root, src_path, temp_dir, mock_env_vars) - Path configuration for imports - Add test_pytest_config.py with 12 unit tests - All tests passing (12/12) Refs: T05 Completes setup phase T01-T05
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
"""Pytest configuration and fixtures.
|
||||
|
||||
This module contains shared fixtures and configuration for all tests.
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
# Add src to path for importing in tests
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
|
||||
|
||||
# Markers for test organization
|
||||
pytest_plugins = ['pytest_asyncio']
|
||||
|
||||
|
||||
def pytest_configure(config):
|
||||
"""Configure pytest with custom markers."""
|
||||
config.addinivalue_line("markers", "unit: Unit tests (no external dependencies)")
|
||||
config.addinivalue_line("markers", "integration: Integration tests (with mocked dependencies)")
|
||||
config.addinivalue_line("markers", "e2e: End-to-end tests (full workflow)")
|
||||
config.addinivalue_line("markers", "slow: Slow tests (skip in quick mode)")
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def project_root():
|
||||
"""Return the project root directory."""
|
||||
return os.path.dirname(os.path.dirname(__file__))
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def src_path(project_root):
|
||||
"""Return the src directory path."""
|
||||
return os.path.join(project_root, 'src')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def temp_dir(tmp_path):
|
||||
"""Provide a temporary directory for tests."""
|
||||
return tmp_path
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_env_vars(monkeypatch):
|
||||
"""Set up mock environment variables for testing."""
|
||||
monkeypatch.setenv('SECRET_KEY', 'test-secret-key-min-32-characters-long')
|
||||
monkeypatch.setenv('ENCRYPTION_KEY', 'test-32-byte-encryption-key!!')
|
||||
monkeypatch.setenv('DATABASE_URL', 'sqlite:///./test.db')
|
||||
monkeypatch.setenv('DEBUG', 'true')
|
||||
monkeypatch.setenv('LOG_LEVEL', 'DEBUG')
|
||||
|
||||
Reference in New Issue
Block a user