Skip to content

Commit 726c1c5

Browse files
committed
Add test for logdir and environment variable priority
Introduces a test to verify that when the user-provided logdir differs from the environment variable, settings are read from the environment variable as expected.
1 parent 983b073 commit 726c1c5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/unit/data/test_sdk.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,18 @@ def test_init_folder_mode(self, folder_mode):
263263
assert os.environ[MODE] == folder_mode
264264
run.log({"TestInitMode": 1})
265265

266+
def test_init_folder_mode_diff_logdir(self, tmp_path):
267+
"""用户传入的 logdir 和环境变量不一样,settings 读取走环境变量"""
268+
# 写入文件夹的 settings 文件
269+
os.makedirs(T.SWANLOG_FOLDER, exist_ok=True)
270+
# settings 为默认文件名
271+
with open(os.path.join(T.SWANLOG_FOLDER, "settings"), 'w') as f:
272+
f.write("[default]\nmode={}\n".format('offline'))
273+
with open(os.path.join(tmp_path, "settings"), 'w') as f:
274+
f.write("[default]\nmode={}\n".format('disabled'))
275+
S.init(logdir=tmp_path)
276+
assert os.environ[MODE] == 'offline'
277+
266278
# -------------- 优先级问题(传入的mode参数 > 环境变量 > 设置文件 > 默认值(cloud)) -------------------
267279
def test_init_priority_1(self):
268280
"""

0 commit comments

Comments
 (0)