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.

test: delete 7 no-assert 'should not raise' metrics tests (#4287)

LearningCircuit6bb4992250a8
diff --git a/tests/metrics/test_search_tracker.py b/tests/metrics/test_search_tracker.py
index 7fc700b85a..185c65048b 100644
--- a/tests/metrics/test_search_tracker.py
+++ b/tests/metrics/test_search_tracker.py
@@ -27,19 +27,6 @@ class TestSearchTrackerInit:
class TestSearchTrackerRecordSearch:
"""Tests for record_search static method."""
- def test_skips_when_no_context(self):
- """Should skip recording when no search context."""
- with patch(
- "local_deep_research.metrics.search_tracker.get_search_context",
- return_value=None,
- ):
- # Should not raise and should return without recording
- SearchTracker.record_search(
- engine_name="google",
- query="test query",
- results_count=10,
- )
-
def test_extracts_context_correctly(self, mock_search_context):
"""Should extract research context from thread context."""
mock_session = MagicMock()
@@ -94,34 +81,6 @@ class TestSearchTrackerRecordSearch:
call_args = mock_session.add.call_args[0][0]
assert call_args.research_id == "12345"
- def test_skips_when_no_username(self, mock_search_context):
- """Should skip recording when no username in context."""
- mock_search_context["username"] = None
-
- with patch(
- "local_deep_research.metrics.search_tracker.get_search_context",
- return_value=mock_search_context,
- ):
- # Should not raise
- SearchTracker.record_search(
- engine_name="google",
- query="test",
- )
-
- def test_skips_when_no_password(self, mock_search_context):
- """Should skip recording when no password in context."""
- mock_search_context["user_password"] = None
-
- with patch(
- "local_deep_research.metrics.search_tracker.get_search_context",
- return_value=mock_search_context,
- ):
- # Should not raise
- SearchTracker.record_search(
- engine_name="google",
- query="test",
- )
-
def test_sets_success_status_for_successful_search(
self, mock_search_context
):
diff --git a/tests/metrics/test_search_tracker_coverage.py b/tests/metrics/test_search_tracker_coverage.py
index 8bf2af78ca..48e749cf88 100644
--- a/tests/metrics/test_search_tracker_coverage.py
+++ b/tests/metrics/test_search_tracker_coverage.py
@@ -142,6 +142,71 @@ class TestRecordSearchErrorType:
assert call_obj.error_message is None
+class TestRecordSearchSkipPaths:
+ """Cover the early-return skip paths in record_search."""
+
+ def test_skips_when_context_is_none(self):
+ """No research context -> early return, metrics_writer never invoked."""
+ mock_writer = MagicMock()
+ with patch(
+ "local_deep_research.metrics.search_tracker.get_search_context",
+ return_value=None,
+ ):
+ with patch(
+ "local_deep_research.database.thread_metrics.metrics_writer",
+ mock_writer,
+ ):
+ SearchTracker.record_search(
+ engine_name="brave",
+ query="q",
+ )
+ mock_writer.get_session.assert_not_called()
+ mock_writer.set_user_password.assert_not_called()
+
+ def test_skips_when_username_missing(self):
+ """Context without username -> warning logged, no session opened."""
+ ctx = _base_context()
+ ctx["username"] = None
+ mock_writer = MagicMock()
+ with patch(
+ "local_deep_research.metrics.search_tracker.get_search_context",
+ return_value=ctx,
+ ):
+ with patch(
+ "local_deep_research.database.thread_metrics.metrics_writer",
+ mock_writer,
+ ):
+ with patch(
+ "local_deep_research.metrics.search_tracker.logger"
+ ) as mock_logger:
+ SearchTracker.record_search(
+ engine_name="brave",
+ query="q",
+ )
+ mock_writer.get_session.assert_not_called()
+ mock_logger.warning.assert_called_once()
+
+ def test_skips_when_password_missing(self):
+ """Context with username but no password -> early return before writer."""
+ ctx = _base_context()
+ ctx["user_password"] = None
+ mock_writer = MagicMock()
+ with patch(
+ "local_deep_research.metrics.search_tracker.get_search_context",
+ return_value=ctx,
+ ):
+ with patch(
+ "local_deep_research.database.thread_metrics.metrics_writer",
+ mock_writer,
+ ):
+ SearchTracker.record_search(
+ engine_name="brave",
+ query="q",
+ )
+ mock_writer.get_session.assert_not_called()
+ mock_writer.set_user_password.assert_not_called()
+
+
class TestRecordSearchOuterException:
"""Cover the outer try/except in record_search (line 119)."""
diff --git a/tests/metrics/test_token_counter.py b/tests/metrics/test_token_counter.py
index f8dbf45db2..d130c49c2c 100644
--- a/tests/metrics/test_token_counter.py
+++ b/tests/metrics/test_token_counter.py
@@ -441,26 +441,6 @@ class TestTokenCountingCallbackSaveToDb:
)
mock_writer.write_token_metrics.assert_called()
- def test_skips_save_without_username(self):
- """Should skip save when no username available."""
- callback = TokenCountingCallback(
- research_id="test-uuid",
- research_context={}, # No username
- )
-
- with patch("threading.current_thread") as mock_thread:
- mock_thread.return_value.name = "WorkerThread"
- # Should not raise
- callback._save_to_db(100, 50)
-
- def test_skips_save_without_research_id(self):
- """Should skip save when no research_id."""
- callback = TokenCountingCallback(research_id=None)
- callback.current_model = "gpt-4"
-
- # Should not raise - just returns early
- callback._save_to_db(100, 50)
-
class TestTokenCountingCallbackGetCounts:
"""Tests for get_counts method."""
diff --git a/tests/metrics/test_token_counter_llm_paths_coverage.py b/tests/metrics/test_token_counter_llm_paths_coverage.py
index d1fd504be0..71bde845d5 100644
--- a/tests/metrics/test_token_counter_llm_paths_coverage.py
+++ b/tests/metrics/test_token_counter_llm_paths_coverage.py
@@ -774,13 +774,6 @@ class TestSaveToDbNoUsername:
mock_warn.assert_called_once()
- def test_no_username_does_not_raise(self):
- cb = _make_callback(research_context={})
-
- with _patch_worker_thread():
- # Must not raise even without username
- cb._save_to_db(100, 50)
-
# ---------------------------------------------------------------------------
# 9. test_save_to_db_no_password
@@ -817,12 +810,6 @@ class TestSaveToDbNoPassword:
mock_warn.assert_called_once()
- def test_no_password_does_not_raise(self):
- cb = _make_callback(research_context={"username": "bob"})
-
- with _patch_worker_thread():
- cb._save_to_db(100, 50) # should return quietly
-
# ---------------------------------------------------------------------------
# 10. test_save_to_db_success