{"uid":"cap_YRwg0P0b9D2qqhcDQoYHb","slug":"saylor-innovations-guide-library-pytest-mocking-patching-1f79e853","name":"Saylor Innovations Guide Library – Pytest Mocking & Patching","description":"Pytest mocking - patch where the name is used, autospec to catch bad calls, side_effect for retries, monkeypatch, freezegun","url":"https://saylorinnovations.com/api/kb/pytest-mock-patch-where-used-autospec-monkeypatch?utm_source=zero.xyz","method":"GET","headers":{},"bodySchema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["input"],"properties":{"input":{"type":"object","required":["type","method"],"properties":{"type":{"type":"string","const":"http"},"method":{"enum":["GET"],"type":"string"}},"additionalProperties":false},"output":{"type":"object","required":["type"],"properties":{"type":{"type":"string","const":"json"},"example":{"type":"object","required":["id","t","c","body"],"properties":{"c":{"type":"string","description":"Category of the guide"},"t":{"type":"string","description":"Title of the guide"},"id":{"type":"string","description":"Identifier of the record"},"body":{"type":"string","description":"Main body text"},"price":{"type":["number","null"],"description":"Price"},"license":{"type":"string","description":"License identifier"}}}}}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.01","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.01/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.01","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.01","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_h5IO4Vv_Obw-AMelncKdk","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.01","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Returns a knowledge-base article explaining pytest mocking best practices: patch-where-used, autospec, side_effect for retries, monkeypatch, and freezegun","exampleAgentPrompt":"Pull up the Saylor Innovations guide on pytest mocking — I need to understand how to use patch correctly, autospec to catch bad calls, side_effect for retry simulation, monkeypatch, and freezegun.","exampleUseCases":[{"title":"Learning pytest patch best practices","prompt":"I keep patching in the wrong place in my tests — can you fetch me a guide that explains where to apply patch in pytest and the difference between patching by name location versus import location?"},{"title":"Simulating retries with side_effect","prompt":"I need to test a function that retries on failure — grab me the pytest guide on using side_effect to simulate retry sequences so I can see a working example."},{"title":"Freezing time in date-sensitive tests","prompt":"My tests break depending on what day it's run because they depend on the current date — fetch me the guide on using freezegun with pytest so I can lock time in my test suite."}],"resultDescription":"A JSON object containing the guide's unique ID, title, category, full body text with explanations and examples of pytest mocking techniques (patch placement, autospec, side_effect for retries, monkeypatch, freezegun), along with a license identifier and optional price field.","failureModes":["Payment not received or x402 auth missing — returns 402 Payment Required","Guide not found at this path — returns 404 Not Found","Service temporarily unavailable — returns 503","Rate limiting exceeded — returns 429"],"whenToPreferThis":"Choose this endpoint when an agent or developer needs an authoritative, self-contained reference article specifically covering pytest mocking patterns (patch-where-used, autospec, side_effect, monkeypatch, freezegun) without scraping the open web. Useful for agents building developer tooling, code-review bots, or tutorial assistants that need reliable, licensed content about Python testing.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-21T07:25:40.240Z","isFirstParty":false,"canonicalSlug":"saylor-innovations-guide-library-pytest-mocking-patching-1f79e853"}