Skip to content

fix: Fix n8n integration test mocking issues#21

Merged
MervinPraison merged 1 commit intomainfrom
claude/issue-20-20260416-1734
Apr 16, 2026
Merged

fix: Fix n8n integration test mocking issues#21
MervinPraison merged 1 commit intomainfrom
claude/issue-20-20260416-1734

Conversation

@MervinPraison
Copy link
Copy Markdown
Owner

@MervinPraison MervinPraison commented Apr 16, 2026

Fixes #20

This PR fixes the test mocking issues in the n8n integration that were causing 2 test failures.

Changes

  • Fixed test_n8n_workflow_missing_httpx to use sys.modules approach for lazy import mocking
  • Enhanced mock_httpx fixture with proper HTTPStatusError and TimeoutException classes
  • All 14 tests now pass (12 passed, 2 integration tests correctly skipped)

Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Improved test fixture infrastructure to better simulate missing dependency conditions and exception scenarios.
    • Refined test methodology for validating error handling when required external libraries are unavailable.

- 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: Mervin Praison <MervinPraison@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 16, 2026 17:41
Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MervinPraison has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@MervinPraison MervinPraison merged commit 4ad5166 into main Apr 16, 2026
1 of 5 checks passed
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 16, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e965d927-131a-4f89-829b-bf793836c08e

📥 Commits

Reviewing files that changed from the base of the PR and between 442a0d7 and a2d7590.

📒 Files selected for processing (1)
  • tests/test_n8n_integration.py

📝 Walkthrough

Walkthrough

Updated the mock_httpx pytest fixture to properly intercept lazy httpx imports by defining TimeoutException and HTTPStatusError exception classes. Modified test_n8n_workflow_missing_httpx to use sys.modules patching instead of direct module patching.

Changes

Cohort / File(s) Summary
Test Fixture & Missing Import Test
tests/test_n8n_integration.py
Enhanced mock_httpx fixture with custom exception class definitions for TimeoutException and HTTPStatusError. Updated test_n8n_workflow_missing_httpx to patch sys.modules with {'httpx': None} and force ImportError via builtins.__import__ for proper lazy import simulation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 The fixtures dance with mocks so bright,
sys.modules patched just right,
HTTPStatusError now takes its place,
No more lazy import's face!
Tests will pass with gleeful cheer, 🎉

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/issue-20-20260416-1734

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes failing n8n integration unit tests by improving how the lazy httpx import is mocked and by providing mock exception types that match what the implementation catches.

Changes:

  • Updated the mock_httpx fixture to provide TimeoutException and HTTPStatusError types compatible with the n8n tool’s exception handling.
  • Switched the “missing httpx” test to a sys.modules-based approach for simulating an unavailable dependency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


mock_module.HTTPStatusError = MockHTTPStatusError

with patch.dict('sys.modules', {'httpx': mock_module}) as mock_modules:
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

patch.dict('sys.modules', {'httpx': mock_module}) as mock_modules binds mock_modules but it’s never used, which adds noise (and can trip linters). Drop the as mock_modules binding (or use it) to keep the fixture minimal.

Suggested change
with patch.dict('sys.modules', {'httpx': mock_module}) as mock_modules:
with patch.dict('sys.modules', {'httpx': mock_module}):

Copilot uses AI. Check for mistakes.
Comment on lines +85 to 87
with patch.dict('sys.modules', {'httpx': None}):
with patch('builtins.__import__', side_effect=ImportError("No module named 'httpx'")):
result = tool.run(workflow_id="test-workflow")
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patching builtins.__import__ with a blanket ImportError makes this test overly broad: if tool.run() (or anything it calls) adds any other import, the test will still pass even though the failure wasn’t specifically due to missing httpx. Prefer relying on the sys.modules['httpx']=None behavior alone, or make the __import__ side effect conditional so it only fails when importing httpx.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the n8n integration tests by improving the httpx mock fixture with specific exception classes and updating the simulation of missing dependencies using sys.modules. A review comment suggests that patching builtins.__import__ is redundant when sys.modules['httpx'] is already set to None, recommending its removal to simplify the test and avoid potential side effects.

tool = N8nWorkflowTool()
with patch('praisonai_tools.n8n.n8n_workflow.httpx', None):
# Mock the import failure using sys.modules approach
with patch.dict('sys.modules', {'httpx': None}):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The patch on builtins.__import__ (line 86) is redundant when sys.modules['httpx'] is set to None. Setting a module to None in sys.modules is the standard way to simulate a missing module in Python and will cause an ImportError immediately upon an import httpx statement. Removing the redundant patch simplifies the test and avoids the potential side effects of patching a core builtin like __import__.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

n8n Integration: Fix Test Mocking Issues

2 participants