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
This commit is contained in:
yusyus
2025-12-21 20:52:13 +03:00
parent 3e40a5159e
commit ae69c507a0
2 changed files with 25 additions and 2 deletions

View File

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

View File

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