From 13cc453e9d0eac5812cae00422be169afcc78e4e Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Fri, 19 Dec 2025 12:35:06 +0200 Subject: [PATCH] Make tests ignore haiku.rag.yaml --- tests/conftest.py | 15 ++++++++++++--- tests/test_config.py | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 87bf19b8..46bef799 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,18 @@ +import os import tempfile from pathlib import Path -import pytest -import yaml -from datasets import Dataset, load_dataset, load_from_disk +# Prevent tests from loading user's local haiku.rag.yaml by setting env var +# to an empty config file BEFORE any haiku.rag imports. +# This ensures tests always use default config values. +_test_config_dir = tempfile.mkdtemp() +_test_config_path = Path(_test_config_dir) / "test-defaults.yaml" +_test_config_path.write_text("{}") # Empty YAML = use all defaults +os.environ["HAIKU_RAG_CONFIG_PATH"] = str(_test_config_path) + +import pytest # noqa: E402 +import yaml # noqa: E402 +from datasets import Dataset, load_dataset, load_from_disk # noqa: E402 @pytest.fixture(scope="session") diff --git a/tests/test_config.py b/tests/test_config.py index 70cf98c7..4932a6f3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -30,6 +30,7 @@ embeddings: def test_find_config_file_cwd(tmp_path, monkeypatch): """Test finding config in current directory.""" + monkeypatch.delenv("HAIKU_RAG_CONFIG_PATH", raising=False) monkeypatch.chdir(tmp_path) config_file = tmp_path / "haiku.rag.yaml" config_file.write_text("environment: production") @@ -40,6 +41,7 @@ def test_find_config_file_cwd(tmp_path, monkeypatch): def test_find_config_file_user_config(tmp_path, monkeypatch): """Test finding config in user config directory.""" + monkeypatch.delenv("HAIKU_RAG_CONFIG_PATH", raising=False) monkeypatch.chdir(tmp_path) # Mock get_default_data_dir to return tmp_path @@ -79,6 +81,7 @@ def test_find_config_file_env_var(tmp_path, monkeypatch): def test_find_config_file_not_found(tmp_path, monkeypatch): """Test returning None when no config found.""" + monkeypatch.delenv("HAIKU_RAG_CONFIG_PATH", raising=False) monkeypatch.chdir(tmp_path) # Mock get_default_data_dir to return tmp_path @@ -103,6 +106,8 @@ def test_find_config_file_cli_path_not_exists(tmp_path): def test_config_precedence_cwd_over_user(tmp_path, monkeypatch): """Test that cwd config takes precedence over user config.""" + monkeypatch.delenv("HAIKU_RAG_CONFIG_PATH", raising=False) + # Create separate directories for cwd and user config cwd_dir = tmp_path / "cwd" cwd_dir.mkdir()