fabioc-aloha/alex_skill_mall/python-mock-patching-location
- community
Checking that the SKILL.md file is still in the repository.
Python mock.patch must target the import location, not the definition location
Install
npx vskill@latest install fabioc-aloha/alex_skill_mall/python-mock-patching-locationSKILL.md
Python Mock Patching Location
Category: Testing Time Saved: 30+ minutes debugging "mock not working" Battle-tested: Yes — ChessCoach, multiple Python projects
The Problem
You're writing a test that needs to mock get_client() from module_a. You patch module_a.get_client. The mock doesn't work — the real function still runs.
Why It Happens
Python's import system creates a reference to the function in the importing module. When module_b does from module_a import get_client, it creates module_b.get_client as a separate reference. Patching the original doesn't affect the copy.
The Rule
Patch where the function is USED, not where it's DEFINED
Decision Table
| Import Style in Target Module | Patch Target | |
|---|---|---|
from module_a import func | target_module.func | |
import module_a then module_a.func() | module_a.func | |
from module_a import func as alias | target_module.alias |
Async Context Manager Trap
MagicMock doesn't support async with by default:
Verification
Test passes AND you've confirmed the mock was actually called:
If assert_called_once() fails with "Expected call not found", you patched the wrong location.
Source: Promoted from AI-Memory global-knowledge.md (2026-04-27)
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingplugins/code-quality/python-mock-patching-location/skills/python-mock-patching-location/SKILL.md
Popularity
- Repository stars
- 4
- Repository forks
- 1
- 7-day trend score
- 13
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/fabioc-aloha/alex_skill_mall/python-mock-patching-location)