fix(tests): Correctly patch fetch functions in test_app.py

- Patch  instead of
- Add missing patches for  and  in background threads
- Prevent network I/O during tests
This commit is contained in:
2026-03-19 23:20:32 -07:00
parent 7eaa441574
commit ad8513f2f6

View File

@@ -69,9 +69,11 @@ class TestRunPipelineMode:
"""run_pipeline_mode() exits if no content can be fetched.""" """run_pipeline_mode() exits if no content can be fetched."""
with ( with (
patch("engine.app.pipeline_runner.load_cache", return_value=None), patch("engine.app.pipeline_runner.load_cache", return_value=None),
patch("engine.app.pipeline_runner.fetch_all_fast", return_value=[]),
patch( patch(
"engine.app.pipeline_runner.fetch_all", return_value=([], None, None) "engine.app.pipeline_runner.fetch_all", return_value=([], None, None)
), ), # Mock background thread
patch("engine.app.pipeline_runner.save_cache"), # Prevent disk I/O
patch("engine.effects.plugins.discover_plugins"), patch("engine.effects.plugins.discover_plugins"),
pytest.raises(SystemExit) as exc_info, pytest.raises(SystemExit) as exc_info,
): ):
@@ -86,6 +88,7 @@ class TestRunPipelineMode:
"engine.app.pipeline_runner.load_cache", return_value=cached "engine.app.pipeline_runner.load_cache", return_value=cached
) as mock_load, ) as mock_load,
patch("engine.app.pipeline_runner.fetch_all") as mock_fetch, patch("engine.app.pipeline_runner.fetch_all") as mock_fetch,
patch("engine.app.pipeline_runner.fetch_all_fast"),
patch("engine.app.pipeline_runner.DisplayRegistry.create") as mock_create, patch("engine.app.pipeline_runner.DisplayRegistry.create") as mock_create,
): ):
mock_display = Mock() mock_display = Mock()
@@ -109,7 +112,8 @@ class TestRunPipelineMode:
def test_run_pipeline_mode_creates_display(self): def test_run_pipeline_mode_creates_display(self):
"""run_pipeline_mode() creates a display backend.""" """run_pipeline_mode() creates a display backend."""
with ( with (
patch("engine.app.load_cache", return_value=["item"]), patch("engine.app.pipeline_runner.load_cache", return_value=["item"]),
patch("engine.app.pipeline_runner.fetch_all_fast", return_value=[]),
patch("engine.app.DisplayRegistry.create") as mock_create, patch("engine.app.DisplayRegistry.create") as mock_create,
): ):
mock_display = Mock() mock_display = Mock()
@@ -134,7 +138,8 @@ class TestRunPipelineMode:
sys.argv = ["mainline.py", "--display", "websocket"] sys.argv = ["mainline.py", "--display", "websocket"]
with ( with (
patch("engine.app.load_cache", return_value=["item"]), patch("engine.app.pipeline_runner.load_cache", return_value=["item"]),
patch("engine.app.pipeline_runner.fetch_all_fast", return_value=[]),
patch("engine.app.DisplayRegistry.create") as mock_create, patch("engine.app.DisplayRegistry.create") as mock_create,
): ):
mock_display = Mock() mock_display = Mock()
@@ -163,6 +168,7 @@ class TestRunPipelineMode:
return_value=(["poem"], None, None), return_value=(["poem"], None, None),
) as mock_fetch_poetry, ) as mock_fetch_poetry,
patch("engine.app.pipeline_runner.fetch_all") as mock_fetch_all, patch("engine.app.pipeline_runner.fetch_all") as mock_fetch_all,
patch("engine.app.pipeline_runner.fetch_all_fast", return_value=[]),
patch("engine.app.pipeline_runner.DisplayRegistry.create") as mock_create, patch("engine.app.pipeline_runner.DisplayRegistry.create") as mock_create,
): ):
mock_display = Mock() mock_display = Mock()
@@ -187,6 +193,7 @@ class TestRunPipelineMode:
"""run_pipeline_mode() discovers available effect plugins.""" """run_pipeline_mode() discovers available effect plugins."""
with ( with (
patch("engine.app.pipeline_runner.load_cache", return_value=["item"]), patch("engine.app.pipeline_runner.load_cache", return_value=["item"]),
patch("engine.app.pipeline_runner.fetch_all_fast", return_value=[]),
patch("engine.effects.plugins.discover_plugins") as mock_discover, patch("engine.effects.plugins.discover_plugins") as mock_discover,
patch("engine.app.pipeline_runner.DisplayRegistry.create") as mock_create, patch("engine.app.pipeline_runner.DisplayRegistry.create") as mock_create,
): ):