From ae69c507a0df462fefcf01555b35b8d7fe411bbd Mon Sep 17 00:00:00 2001 From: yusyus Date: Sun, 21 Dec 2025 20:52:13 +0300 Subject: [PATCH] fix: Add defensive imports for MCP package in install_skill tests - Added try/except around 'from mcp.types import TextContent' in test files - Added @pytest.mark.skipif decorator to all test classes - Tests now gracefully skip if MCP package is not installed - Fixes ModuleNotFoundError during test collection in CI This follows the same pattern used in test_mcp_server.py (lines 21-31). All tests pass locally: 23 passed, 1 skipped --- tests/test_install_skill.py | 15 ++++++++++++++- tests/test_install_skill_e2e.py | 12 +++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/test_install_skill.py b/tests/test_install_skill.py index 97b2286..3f77f60 100644 --- a/tests/test_install_skill.py +++ b/tests/test_install_skill.py @@ -13,12 +13,20 @@ Tests the complete workflow orchestration for A1.7: import asyncio import pytest from unittest.mock import AsyncMock, MagicMock, patch -from mcp.types import TextContent + +# Defensive import for MCP package (may not be installed in all environments) +try: + from mcp.types import TextContent + MCP_AVAILABLE = True +except ImportError: + MCP_AVAILABLE = False + TextContent = None # Placeholder # Import the function to test from skill_seekers.mcp.server import install_skill_tool +@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed") class TestInstallSkillValidation: """Test input validation""" @@ -46,6 +54,7 @@ class TestInstallSkillValidation: assert "Choose one:" in result[0].text +@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed") class TestInstallSkillDryRun: """Test dry-run mode""" @@ -100,6 +109,7 @@ class TestInstallSkillDryRun: assert "Fetch Config" not in output +@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed") class TestInstallSkillEnhancementMandatory: """Test that enhancement is always included""" @@ -123,6 +133,7 @@ class TestInstallSkillEnhancementMandatory: assert "no skip option" in output.lower() or "MANDATORY" in output +@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed") class TestInstallSkillPhaseOrchestration: """Test phase orchestration and data flow""" @@ -267,6 +278,7 @@ class TestInstallSkillPhaseOrchestration: assert "Manual upload:" in output +@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed") class TestInstallSkillErrorHandling: """Test error handling at each phase""" @@ -351,6 +363,7 @@ class TestInstallSkillErrorHandling: assert "exit code 1" in output +@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed") class TestInstallSkillOptions: """Test various option combinations""" diff --git a/tests/test_install_skill_e2e.py b/tests/test_install_skill_e2e.py index 736450f..1e08793 100644 --- a/tests/test_install_skill_e2e.py +++ b/tests/test_install_skill_e2e.py @@ -47,12 +47,20 @@ from pathlib import Path from unittest.mock import patch, MagicMock import pytest -from mcp.types import TextContent + +# Defensive import for MCP package (may not be installed in all environments) +try: + from mcp.types import TextContent + MCP_AVAILABLE = True +except ImportError: + MCP_AVAILABLE = False + TextContent = None # Placeholder # Import the MCP tool to test from skill_seekers.mcp.server import install_skill_tool +@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed") class TestInstallSkillE2E: """End-to-end tests for install_skill MCP tool""" @@ -303,6 +311,7 @@ class TestInstallSkillE2E: assert "exit code 1" in output +@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed") class TestInstallSkillCLI_E2E: """End-to-end tests for skill-seekers install CLI""" @@ -449,6 +458,7 @@ class TestInstallSkillCLI_E2E: f"Unified CLI failed:\nSTDOUT:\n{result.stdout}\nSTDERR:\n{result.stderr}" +@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed") class TestInstallSkillE2E_RealFiles: """E2E tests with real file operations (no mocking except upload)"""