From e8dd065ad724a24270d05ccf0d9a56bda4e1220a Mon Sep 17 00:00:00 2001 From: hermes Date: Sun, 15 Mar 2026 12:17:50 -0400 Subject: [PATCH] [loop-cycle-51] perf: mock subprocess in slow introspection test (#172) (#184) --- tests/e2e/test_ollama_integration.py | 1 + tests/timmy/test_introspection.py | 34 ++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/tests/e2e/test_ollama_integration.py b/tests/e2e/test_ollama_integration.py index 6fd8b82..0ec09b6 100644 --- a/tests/e2e/test_ollama_integration.py +++ b/tests/e2e/test_ollama_integration.py @@ -53,6 +53,7 @@ async def test_model_fallback_chain(): assert model == "nonexistent-model" +@pytest.mark.ollama @pytest.mark.asyncio async def test_timmy_agent_with_available_model(): """Test that Timmy agent can be created with an available model.""" diff --git a/tests/timmy/test_introspection.py b/tests/timmy/test_introspection.py index c91989a..4c2211e 100644 --- a/tests/timmy/test_introspection.py +++ b/tests/timmy/test_introspection.py @@ -3,7 +3,6 @@ from unittest.mock import MagicMock, patch import httpx -import pytest def test_get_system_info_returns_dict(): @@ -164,19 +163,36 @@ class TestGetOllamaModelExactMatch: class TestRunSelfTests: """Tests for run_self_tests() — Timmy's self-verification tool.""" - @pytest.mark.slow - def test_returns_dict_with_expected_keys(self): + def test_returns_dict_with_expected_keys(self, monkeypatch, tmp_path): """run_self_tests should return structured test results.""" + import subprocess + + def mock_run(*args, **kwargs): + return subprocess.CompletedProcess( + args=args[0] if args else [], + returncode=0, + stdout="5 passed in 0.5s", + stderr="", + ) + + monkeypatch.setattr(subprocess, "run", mock_run) + + # Create fake venv so check passes + venv_python = tmp_path / ".venv" / "bin" / "python" + venv_python.parent.mkdir(parents=True) + venv_python.write_text("#!/bin/sh\necho mock") + from timmy.tools_intro import run_self_tests - result = run_self_tests(scope="tests/timmy/test_introspection.py") + result = run_self_tests(scope="tests/timmy/test_introspection.py", _repo_root=str(tmp_path)) assert isinstance(result, dict) assert "success" in result - # Should have count keys when tests ran - if result["success"] or "passed" in result: - assert "passed" in result - assert "failed" in result - assert "total" in result + assert result["success"] is True + assert "passed" in result + assert "failed" in result + assert "total" in result + assert result["passed"] == 5 + assert result["total"] == 5 def test_fast_scope_skips_integration(self, monkeypatch, tmp_path): """Fast scope should exclude functional/e2e/integration dirs."""