Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix: Enhanced ArXiv test mocking to prevent searxng KeyError in CI (#425)

LearningCircuit1b4f4136c609
diff --git a/tests/run_all_tests.py b/tests/run_all_tests.py
index 73a65df701..26971dea21 100755
--- a/tests/run_all_tests.py
+++ b/tests/run_all_tests.py
@@ -70,7 +70,7 @@ class TestRunner:
print(f"DETAILED ERROR OUTPUT FOR: {name}")
print(f"{'='*60}")
- # Print more detailed output for failures
+ # Print detailed output for failures with full context
if result.stdout:
print("STDOUT:")
lines = result.stdout.strip().split("\n")
@@ -89,17 +89,78 @@ class TestRunner:
):
print(f" {line}")
- # Show specific failed tests
- print("\nFAILED TESTS:")
- for line in lines:
+ # Show specific failed tests with more context
+ print("\nFAILED TESTS WITH CONTEXT:")
+ for i, line in enumerate(lines):
if "FAILED" in line and "::" in line:
print(f" {line.strip()}")
+ # Show next few lines for error details
+ for j in range(i + 1, min(i + 10, len(lines))):
+ if lines[j].strip() and not lines[j].startswith("===="):
+ print(f" {lines[j].strip()}")
+ if "KeyError" in lines[j] or "Exception" in lines[j]:
+ break
+
+ # Show full stack traces for exceptions
+ print("\nFULL STACK TRACES:")
+ in_traceback = False
+ traceback_lines = []
+ for line in lines:
+ if "Traceback (most recent call last):" in line:
+ in_traceback = True
+ traceback_lines = [line]
+ elif in_traceback:
+ traceback_lines.append(line)
+ if line.strip() and not line.startswith(
+ (" ", "\t", "File ", " ")
+ ):
+ # End of traceback
+ for tb_line in traceback_lines:
+ print(f" {tb_line}")
+ print()
+ in_traceback = False
+ traceback_lines = []
+ elif any(
+ error_type in line
+ for error_type in [
+ "KeyError:",
+ "ImportError:",
+ "ModuleNotFoundError:",
+ "AttributeError:",
+ "Exception:",
+ ]
+ ):
+ print(f" ERROR: {line.strip()}")
- # Show import errors
+ # Show import errors with context
print("\nIMPORT ERRORS:")
- for line in lines:
+ for i, line in enumerate(lines):
if "ImportError" in line or "ModuleNotFoundError" in line:
print(f" {line.strip()}")
+ # Show preceding line for context
+ if i > 0:
+ print(f" Context: {lines[i-1].strip()}")
+
+ # Show KeyError details specifically
+ print("\nKEYERROR DETAILS:")
+ for i, line in enumerate(lines):
+ if "KeyError" in line:
+ print(f" {line.strip()}")
+ # Show surrounding context
+ for j in range(max(0, i - 3), min(len(lines), i + 4)):
+ if j != i:
+ print(f" [{j-i:+d}] {lines[j].strip()}")
+
+ # Show pytest short test summary if available
+ print("\nPYTEST SHORT SUMMARY:")
+ in_summary = False
+ for line in lines:
+ if "short test summary info" in line.lower():
+ in_summary = True
+ elif in_summary:
+ if line.startswith("="):
+ break
+ print(f" {line.strip()}")
if result.stderr:
print("\nSTDERR:")
@@ -228,22 +289,52 @@ class TestRunner:
"""Run unit and feature tests."""
self.log("=== UNIT & FEATURE TESTS ===")
+ # Add extra debugging for CI environments
+ pytest_args = [
+ "pdm",
+ "run",
+ "pytest",
+ "-v", # Verbose output
+ "-s", # Don't capture output (show prints)
+ "--tb=long", # Long traceback format
+ "--capture=no", # Don't capture stdout/stderr
+ "--showlocals", # Show local variables in tracebacks
+ "tests/test_settings_manager.py",
+ "tests/test_google_pse.py",
+ "tests/test_wikipedia_url_security.py",
+ "tests/test_search_engines_enhanced.py",
+ "tests/test_utils.py",
+ "tests/feature_tests/",
+ "tests/fix_tests/",
+ "--cov=src",
+ "--cov-report=term-missing",
+ ]
+
+ # In CI, add even more debugging
+ if os.environ.get("CI") or os.environ.get("GITHUB_ACTIONS"):
+ pytest_args.extend(
+ [
+ "--tb=auto", # Automatic traceback selection
+ "-vv", # Extra verbose
+ "--durations=10", # Show 10 slowest tests
+ "--lf", # Run last failed tests first
+ "--ff", # Run failures first
+ "--strict-markers", # Strict marker handling
+ "--strict-config", # Strict config handling
+ ]
+ )
+ self.log("Running with enhanced CI debugging options")
+
+ # Log environment info for debugging
+ self.log(
+ f"CI Environment detected: CI={os.environ.get('CI')}, GITHUB_ACTIONS={os.environ.get('GITHUB_ACTIONS')}"
+ )
+ self.log(f"Python path: {sys.executable}")
+ self.log(f"Working directory: {os.getcwd()}")
+ self.log(f"LDR_USE_FALLBACK_LLM: {os.environ.get('LDR_USE_FALLBACK_LLM')}")
+
return self.run_command(
- [
- "pdm",
- "run",
- "pytest",
- "-v",
- "tests/test_settings_manager.py",
- "tests/test_google_pse.py",
- "tests/test_wikipedia_url_security.py",
- "tests/test_search_engines_enhanced.py",
- "tests/test_utils.py",
- "tests/feature_tests/",
- "tests/fix_tests/",
- "--cov=src",
- "--cov-report=term-missing",
- ],
+ pytest_args,
"Unit & Feature Tests",
timeout=180,
)
diff --git a/tests/test_search_engines_enhanced.py b/tests/test_search_engines_enhanced.py
index 3103235474..a53d5c0548 100644
--- a/tests/test_search_engines_enhanced.py
+++ b/tests/test_search_engines_enhanced.py
@@ -104,7 +104,7 @@ class TestArxivSearchEnhanced:
def test_arxiv_search_success(self, monkeypatch, mock_arxiv_response):
"""Test successful arXiv search."""
- # Mock search_config to ensure searxng is available
+ # Mock search_config to ensure searxng is available - patch multiple locations
def mock_search_config():
return {
"searxng": {
@@ -114,10 +114,29 @@ class TestArxivSearchEnhanced:
}
}
+ # Patch multiple potential import locations
monkeypatch.setattr(
"src.local_deep_research.web_search_engines.search_engines_config.search_config",
mock_search_config,
)
+ monkeypatch.setattr(
+ "local_deep_research.web_search_engines.search_engines_config.search_config",
+ mock_search_config,
+ )
+
+ # Also mock the search engine factory create function to avoid the KeyError entirely
+ def mock_create_search_engine(engine_name, **kwargs):
+ from unittest.mock import Mock
+
+ mock_engine = Mock()
+ mock_engine.is_available = True
+ mock_engine.run.return_value = []
+ return mock_engine
+
+ monkeypatch.setattr(
+ "src.local_deep_research.web_search_engines.search_engine_factory.create_search_engine",
+ mock_create_search_engine,
+ )
from src.local_deep_research.web_search_engines.engines.search_engine_arxiv import (
ArXivSearchEngine,