- Add test_config.py with tests for load_settings function - Add test_config.yaml fixture with test database configuration - Tests cover: successful loading, file not found error, database URL generation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
26 lines
832 B
Python
26 lines
832 B
Python
import pytest
|
|
from config.settings import load_settings
|
|
|
|
|
|
def test_load_settings_success():
|
|
"""测试成功加载配置文件"""
|
|
settings = load_settings("tests/fixtures/test_config.yaml")
|
|
assert settings.database.sql_server.port == 1433
|
|
assert settings.database.sql_server.host == "localhost"
|
|
assert settings.database.sql_server.database == "TestDB"
|
|
|
|
|
|
def test_load_settings_file_not_found():
|
|
"""测试配置文件不存在时抛出异常"""
|
|
with pytest.raises(FileNotFoundError):
|
|
load_settings("nonexistent.yaml")
|
|
|
|
|
|
def test_database_url_property():
|
|
"""测试 database_url 属性生成"""
|
|
settings = load_settings("tests/fixtures/test_config.yaml")
|
|
url = settings.database_url
|
|
assert "mssql+pyodbc" in str(url)
|
|
assert "test_user" in str(url)
|
|
assert "TestDB" in str(url)
|