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:
@@ -13,12 +13,20 @@ Tests the complete workflow orchestration for A1.7:
|
|||||||
import asyncio
|
import asyncio
|
||||||
import pytest
|
import pytest
|
||||||
from unittest.mock import AsyncMock, MagicMock, patch
|
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
|
# Import the function to test
|
||||||
from skill_seekers.mcp.server import install_skill_tool
|
from skill_seekers.mcp.server import install_skill_tool
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed")
|
||||||
class TestInstallSkillValidation:
|
class TestInstallSkillValidation:
|
||||||
"""Test input validation"""
|
"""Test input validation"""
|
||||||
|
|
||||||
@@ -46,6 +54,7 @@ class TestInstallSkillValidation:
|
|||||||
assert "Choose one:" in result[0].text
|
assert "Choose one:" in result[0].text
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed")
|
||||||
class TestInstallSkillDryRun:
|
class TestInstallSkillDryRun:
|
||||||
"""Test dry-run mode"""
|
"""Test dry-run mode"""
|
||||||
|
|
||||||
@@ -100,6 +109,7 @@ class TestInstallSkillDryRun:
|
|||||||
assert "Fetch Config" not in output
|
assert "Fetch Config" not in output
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed")
|
||||||
class TestInstallSkillEnhancementMandatory:
|
class TestInstallSkillEnhancementMandatory:
|
||||||
"""Test that enhancement is always included"""
|
"""Test that enhancement is always included"""
|
||||||
|
|
||||||
@@ -123,6 +133,7 @@ class TestInstallSkillEnhancementMandatory:
|
|||||||
assert "no skip option" in output.lower() or "MANDATORY" in output
|
assert "no skip option" in output.lower() or "MANDATORY" in output
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed")
|
||||||
class TestInstallSkillPhaseOrchestration:
|
class TestInstallSkillPhaseOrchestration:
|
||||||
"""Test phase orchestration and data flow"""
|
"""Test phase orchestration and data flow"""
|
||||||
|
|
||||||
@@ -267,6 +278,7 @@ class TestInstallSkillPhaseOrchestration:
|
|||||||
assert "Manual upload:" in output
|
assert "Manual upload:" in output
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed")
|
||||||
class TestInstallSkillErrorHandling:
|
class TestInstallSkillErrorHandling:
|
||||||
"""Test error handling at each phase"""
|
"""Test error handling at each phase"""
|
||||||
|
|
||||||
@@ -351,6 +363,7 @@ class TestInstallSkillErrorHandling:
|
|||||||
assert "exit code 1" in output
|
assert "exit code 1" in output
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed")
|
||||||
class TestInstallSkillOptions:
|
class TestInstallSkillOptions:
|
||||||
"""Test various option combinations"""
|
"""Test various option combinations"""
|
||||||
|
|
||||||
|
|||||||
@@ -47,12 +47,20 @@ from pathlib import Path
|
|||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import patch, MagicMock
|
||||||
|
|
||||||
import pytest
|
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
|
# Import the MCP tool to test
|
||||||
from skill_seekers.mcp.server import install_skill_tool
|
from skill_seekers.mcp.server import install_skill_tool
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed")
|
||||||
class TestInstallSkillE2E:
|
class TestInstallSkillE2E:
|
||||||
"""End-to-end tests for install_skill MCP tool"""
|
"""End-to-end tests for install_skill MCP tool"""
|
||||||
|
|
||||||
@@ -303,6 +311,7 @@ class TestInstallSkillE2E:
|
|||||||
assert "exit code 1" in output
|
assert "exit code 1" in output
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skipif(not MCP_AVAILABLE, reason="MCP package not installed")
|
||||||
class TestInstallSkillCLI_E2E:
|
class TestInstallSkillCLI_E2E:
|
||||||
"""End-to-end tests for skill-seekers install CLI"""
|
"""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}"
|
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:
|
class TestInstallSkillE2E_RealFiles:
|
||||||
"""E2E tests with real file operations (no mocking except upload)"""
|
"""E2E tests with real file operations (no mocking except upload)"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user