Skip to content

Commit 4ad5166

Browse files
fix: Fix n8n integration test mocking issues (#21)
- Fix test_n8n_workflow_missing_httpx to use sys.modules approach for lazy import mocking - Enhance mock_httpx fixture with proper HTTPStatusError and TimeoutException classes - All 14 tests now pass (12 passed, 2 integration tests correctly skipped) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
1 parent 442a0d7 commit 4ad5166

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

tests/test_n8n_integration.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,22 @@ class TestN8nWorkflowTool:
1010

1111
@pytest.fixture
1212
def mock_httpx(self):
13-
# Mock httpx in sys.modules to catch lazy imports
14-
with patch.dict('sys.modules', {'httpx': MagicMock()}) as mock_modules:
15-
mock_httpx = mock_modules['httpx']
16-
yield mock_httpx
13+
"""Mock httpx module for testing."""
14+
mock_module = MagicMock()
15+
16+
# Create proper exception classes
17+
mock_module.TimeoutException = type('TimeoutException', (Exception,), {})
18+
19+
class MockHTTPStatusError(Exception):
20+
def __init__(self, message, request=None, response=None):
21+
super().__init__(message)
22+
self.request = request
23+
self.response = response
24+
25+
mock_module.HTTPStatusError = MockHTTPStatusError
26+
27+
with patch.dict('sys.modules', {'httpx': mock_module}) as mock_modules:
28+
yield mock_module
1729

1830
def test_import_n8n_tools(self):
1931
"""Test that n8n tools can be imported."""
@@ -69,7 +81,8 @@ def test_n8n_workflow_missing_httpx(self):
6981
from praisonai_tools.n8n import N8nWorkflowTool
7082

7183
tool = N8nWorkflowTool()
72-
with patch('praisonai_tools.n8n.n8n_workflow.httpx', None):
84+
# Mock the import failure using sys.modules approach
85+
with patch.dict('sys.modules', {'httpx': None}):
7386
with patch('builtins.__import__', side_effect=ImportError("No module named 'httpx'")):
7487
result = tool.run(workflow_id="test-workflow")
7588
assert "httpx not installed" in result["error"]

0 commit comments

Comments
 (0)