{"slug":"mocking-inprocess-python","title":"mocking-inprocess-python","summary":"Use when the mocking-strategy-roster resolved (inprocess, Python) — the override mocking strategy that replaces a downstream dependency with an in-process double (respx for httpx, responses for requests, or a hand-written fake passed to the app factory) instead of a Microcks cont","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-11-29T00:42:31.489644Z","repo":{"url":"https://github.com/SebastienDegodez/skraft-plugin","stars":17,"forks":3,"license":"GPL-3.0","updatedAt":"2026-11-29T00:18:21Z"},"bodyHtml":"<hr>\n<h2>name: mocking-inprocess-python\ndescription: Use when the mocking-strategy-roster resolved (inprocess, Python) — the override mocking strategy that replaces a downstream dependency with an in-process double (respx for httpx, responses for requests, or a hand-written fake passed to the app factory) instead of a Microcks container. Emits mock wiring only; the business TDD cycle stays with the software-engineer lead.</h2>\n<h1>Mocking — In-process x Python adapter (override)</h1>\n<p>Replaces a downstream dependency the SUT calls with an in-process double in a pytest\nintegration test. Selected when the operator overrides the Microcks default.</p>\n<p>Loaded ONLY when <code>mocking-strategy-roster</code> resolved <code>(inprocess, Python)</code>. When no library is\nnamed, the table below is ordered by priority: take the first row that matches the SUT's HTTP\nclient and whose package is already a dev dependency; otherwise the first row that matches\nthe client.</p>\n<p><strong>Boundary:</strong> mock wiring + integration-test scaffold only. No business TDD, no Object\nCalisthenics enforcement, no provider contract verification.</p>\n<h2>Libraries (table order = priority, top = highest)</h2>\n<table>\n<thead>\n<tr>\n<th>Priority</th>\n<th>Library</th>\n<th>Fits</th>\n<th>Double</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>1</td>\n<td>respx</td>\n<td>the SUT calls through <code>httpx</code></td>\n<td><code>respx.mock(base_url=...)</code> routes answering at the HTTP layer</td>\n</tr>\n<tr>\n<td>2</td>\n<td>responses</td>\n<td>the SUT calls through <code>requests</code></td>\n<td><code>responses.RequestsMock()</code> registered URLs</td>\n</tr>\n<tr>\n<td>3</td>\n<td>fake</td>\n<td>any client behind an application <code>Protocol</code></td>\n<td>a hand-written class passed to the app factory</td>\n</tr>\n</tbody>\n</table>\n<h2>Recipe — respx (httpx)</h2>\n<pre><code># tests/integration/test_{feature}_api.py\nimport httpx\nimport respx\nfrom fastapi.testclient import TestClient\n\nfrom {context}.api.app import create_app\nfrom {context}.api.composition import build\n\nDOWNSTREAM = \"https://rates.example.invalid\"\n\n\ndef test_a_claim_above_the_limit_waits_for_approval() -&gt; None:\n    with respx.mock(base_url=DOWNSTREAM, assert_all_called=True) as downstream:\n        downstream.get(\"/rates/USD\").mock(return_value=httpx.Response(200, json={\"rate\": 1.08}))\n        client = TestClient(create_app(build(downstream_base_url=DOWNSTREAM)))\n\n        response = client.post(\"/claims\", json={\"employee_id\": \"e1\", \"amount\": \"1200\", \"currency\": \"USD\"})\n\n    assert response.json()[\"status\"] == \"awaiting_approval\"\n</code></pre>\n<p><code>responses</code> follows the same shape with <code>responses.RequestsMock()</code> and <code>rsps.add(...)</code>.\nA <code>fake</code> replaces the client object itself: <code>build(rates=FixedRates(1.08))</code>.</p>\n<h2>Structured result back to the lead</h2>\n<p>Return, do not commit:</p>\n<pre><code>strategy: inprocess\nstack: python\nlibrary: respx | responses | fake\nfiles:\n  - tests/integration/test_{feature}_api.py\ntestCommand: &lt;resolved via resolving-stack-commands&gt;\nnotes: in-process double for the {downstream} client, injected through the app factory\n</code></pre>\n<h2>Rules</h2>\n<ul>\n<li>Double the DOWNSTREAM client, never the SUT's own domain or use cases.</li>\n<li>This is an INTEGRATION-test double at the HTTP boundary; <code>unittest.mock</code> and <code>pytest-mock</code>\nstay out of the core and <code>tests/unit</code> (G7).</li>\n<li>Inject through the app factory's wiring; never <code>monkeypatch</code> a module attribute.</li>\n<li>Use <code>resolving-stack-commands</code> for the test command — never hardcode <code>pytest</code>.</li>\n</ul>\n","files":[{"path":"SKILL.md","sizeBytes":3179,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-11-29T00:44:06.58436Z","sha256":"404F4C545F6E953FF0BEECC19D909018E4CB6BA925559AA1DBB1150D5A06072A","sizeBytes":1649},"review":null,"source":{"repositoryUrl":"https://github.com/SebastienDegodez/skraft-plugin","path":"plugins/skraft-framework/skills/mocking-inprocess-python","license":"GPL-3.0","commit":"c6117c6236a25490bf1916b131866069740c9b22","subtreeSha":"6FE90DC2E46C375DA892775820349F4E836A6155D0C4D2E04E9C2B7CB90B3B91","lastSyncedAt":"2026-11-29T00:42:27.348488Z"},"reviewedAt":"2026-11-29T00:47:35.781472Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/SebastienDegodez/skraft-plugin/tree/main/plugins/skraft-framework/skills/mocking-inprocess-python"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install sebastiendegodez-skraft-plugin@llmmart"},{"target":"git","command":"git clone https://github.com/SebastienDegodez/skraft-plugin.git"}]}