用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/vladkesler/initrunner --skill mocking-strategies命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | mocking-strategies |
| description | Mock, patch, fake, and stub patterns for isolating dependencies in Python and JavaScript test suites. |
Mocking strategies for isolating external dependencies in tests.
Use this skill when tests need to isolate external dependencies such as databases, APIs, filesystems, time, or randomness.
unittest.mock.patch("module.path.ClassName") -- replace an object for
the duration of a test. Use as a decorator or context manager.patch.object(obj, "attr") -- patch a specific attribute on a live
object.MagicMock(spec=RealClass) -- create a mock that mirrors the real class
API; accessing non-existent attributes raises AttributeError.side_effect -- set to a function for dynamic return values, or to an
exception class to simulate errors.return_value -- set the fixed return value of the mock.monkeypatch (pytest built-in) -- set attributes, environment variables,
or dict items for the duration of a test without import-path gymnastics.jest.mock("module") / vi.mock("module") -- auto-mock an entire
module. Provide a factory function for custom behavior.__mocks__/ -- place a file next to node_modules or
the real module to override it project-wide.msw (Mock Service Worker) -- intercept HTTP at the network level for
realistic API mocking without changing application code.datetime.now, Date.now).mock.assert_called_once_with(arg1, arg2),
mock.call_count, mock.call_args_list.expect(fn).toHaveBeenCalledTimes(1),
expect(fn).toHaveBeenCalledWith(arg1, arg2).spec=True (Python) so the mock rejects calls to methods that do not
exist on the real object.open is fine for filesystem isolation, but mocking len is
not).