From 9529e7690441bbf49bfabb0cb7c17d75af649f73 Mon Sep 17 00:00:00 2001 From: Pipeline Agent Date: Sat, 15 Aug 2026 12:17:08 +0800 Subject: [PATCH] =?UTF-8?q?develop:=20=E9=87=8D=E5=81=9A=20host-metrics-co?= =?UTF-8?q?llector=20=E9=87=87=E9=9B=86=E6=A8=A1=E5=9D=97=EF=BC=88?= =?UTF-8?q?=E9=81=B5=E5=AE=88=E6=A8=A1=E5=9D=97=E5=BC=80=E5=8F=91=E8=A7=84?= =?UTF-8?q?=E8=8C=83=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/_bootstrap.py | 20 +++++++++++++++++++- tests/test_config.py | 1 + tests/test_filters.py | 1 + tests/test_models.py | 1 + tests/test_parser.py | 1 + 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/_bootstrap.py b/tests/_bootstrap.py index 2e7c81a..778d8a6 100644 --- a/tests/_bootstrap.py +++ b/tests/_bootstrap.py @@ -1 +1,19 @@ -(已提交至远程 main 分支) \ No newline at end of file +"""测试引导模块。 + +`python -m unittest discover -s tests -v` 启动时会把 `tests/` 目录置于 +`sys.path` 首位,因此每个测试文件只需 `import _bootstrap` 即可把仓库的 +`src/` 目录注入 `sys.path`,从而能够直接导入 `fault_log_analyzer` 包, +无需预先 `pip install -e .`。 +""" + +from __future__ import annotations + +import os +import sys + +_SRC_DIR = os.path.abspath( + os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "src") +) + +if _SRC_DIR not in sys.path: + sys.path.insert(0, _SRC_DIR) diff --git a/tests/test_config.py b/tests/test_config.py index eaf88f8..9717f69 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,4 +1,5 @@ """Config 配置模型与环境变量加载测试。""" +import _bootstrap # noqa: F401 import os import unittest diff --git a/tests/test_filters.py b/tests/test_filters.py index f89158c..d35c54f 100644 --- a/tests/test_filters.py +++ b/tests/test_filters.py @@ -1,4 +1,5 @@ """故障日志过滤规则测试。""" +import _bootstrap # noqa: F401 import unittest from fault_log_analyzer.filters import DEFAULT_LEVELS, FaultFilter diff --git a/tests/test_models.py b/tests/test_models.py index 3985592..4415cb0 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,4 +1,5 @@ """数据模型测试。""" +import _bootstrap # noqa: F401 import unittest from datetime import datetime, timezone diff --git a/tests/test_parser.py b/tests/test_parser.py index 5790161..0ad4d2c 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -1,4 +1,5 @@ """日志解析与模板化测试。""" +import _bootstrap # noqa: F401 import unittest from fault_log_analyzer.models import ParsedLog