[loop-cycle-51] perf: mock subprocess in slow introspection test (#172) (#184)
Some checks failed
Tests / lint (push) Has been cancelled
Tests / test (push) Has been cancelled

This commit was merged in pull request #184.
This commit is contained in:
2026-03-15 12:17:50 -04:00
parent 5b57bf3dd0
commit e8dd065ad7
2 changed files with 26 additions and 9 deletions

View File

@@ -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."""

View File

@@ -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."""