{"enrichment":{"faq":[{"a":"Pytest Mocking Strategy teaches a decision-driven framework that separates external boundaries from business logic. The core approach: mock external dependencies, test the unit in isolation. Key strategies include using autospec enforcement to catch interface changes, async mock patterns for concurrent code, and reusable mock factories to reduce duplication. This golden rule ensures your tests survive refactoring by validating behavior without coupling to implementation details.","q":"What mocking strategies should I use in pytest?"},{"a":"Pytest Mocking Strategy covers best practices for mocking that center on isolating dependencies during testing. Use autospec to enforce mock contracts, apply async mock patterns when testing concurrent operations, and build reusable mock factories for consistency. The skill emphasizes a clear matrix for what to mock versus what to test directly\u2014mock external boundaries (APIs, databases, file systems) while testing your business logic in isolation.","q":"How do I mock in pytest effectively?"},{"a":"Pytest Mocking Strategy outlines best practices including autospec enforcement to prevent interface drift, async mock patterns for modern async code, and mock fixtures for reusable test doubles. The framework prioritizes mocking external dependencies while testing core logic directly. This approach ensures tests remain maintainable, catch real integration issues, and don't break when internal implementation changes.","q":"What are pytest mock best practices?"},{"a":"Pytest Mocking Strategy teaches you to implement test doubles through reusable mock factories and a structured decision matrix. Use autospec to create mocks that enforce the real interface, apply async mock patterns for concurrent scenarios, and organize mock setup in fixtures. This skill ensures your mock objects accurately represent dependencies without becoming brittle or overly complex.","q":"How do I implement effective test doubles and mock objects?"},{"a":"Pytest Mocking Strategy provides patterns for isolating dependencies by mocking external boundaries\u2014APIs, databases, file systems\u2014while keeping your unit logic under test. Use mock fixtures for reusable test doubles, autospec to enforce contracts, and async mock patterns for concurrent code. This isolation ensures your tests validate business logic independently and catch real integration issues separately.","q":"How do I isolate dependencies during pytest testing?"},{"a":"Pytest Mocking Strategy covers both tools within its framework. Monkeypatch is lighter-weight and ideal for simple replacements in the same process; mock (via unittest.mock) is more powerful for creating sophisticated test doubles with call tracking and autospec enforcement. The skill teaches when to use each: monkeypatch for quick local patches, mock for complex external dependency isolation and contract validation.","q":"What is the difference between pytest monkeypatch and mock?"}],"shadow_tags":["test-doubles","unit-testing","mock-patterns","test-fixtures","dependency-isolation","pytest-plugins","testing-methodology","code-quality"],"summary_rewrite":"Learn a decision-driven framework for mocking in pytest that separates external boundaries from business logic. This skill covers autospec enforcement, async mock patterns, reusable mock factories, and a clear matrix for what to mock versus what to test directly. Master the golden rule\u2014mock external dependencies, test the unit in isolation\u2014to write tests that survive refactoring."},"gist":{"api_url":"https://skillfed.io/api/skills/dawiddutoit/custom-claude/pytest-mocking-strategy.json","as_of":"2026-01-26","description":"Pytest Mocking Strategy teaches when and how to mock dependencies in unit tests, covering autospec, AsyncMock.","install":{"manual":["git clone https://github.com/dawiddutoit/custom-claude","cp -r custom-claude ~/.claude/skills/pytest-mocking-strategy"],"primary":"npx skillfed install dawiddutoit/custom-claude/pytest-mocking-strategy","version":"64b086c3"},"kind":"skill","mirror_url":"https://skillfed.io/dawiddutoit/custom-claude/pytest-mocking-strategy.md","similar":[{"id":"dawiddutoit/custom-claude/pytest-application-layer-testing","name":"Pytest Application Layer Testing","publisher":"dawiddutoit/custom-claude","url":"https://skillfed.io/dawiddutoit/custom-claude/pytest-application-layer-testing"},{"id":"dawiddutoit/custom-claude/pytest-type-safety","name":"Pytest Type Safety","publisher":"dawiddutoit/custom-claude","url":"https://skillfed.io/dawiddutoit/custom-claude/pytest-type-safety"},{"id":"dawiddutoit/custom-claude/pytest-async-testing","name":"Pytest Async Testing","publisher":"dawiddutoit/custom-claude","url":"https://skillfed.io/dawiddutoit/custom-claude/pytest-async-testing"},{"id":"dawiddutoit/custom-claude/pytest-configuration","name":"Pytest Configuration","publisher":"dawiddutoit/custom-claude","url":"https://skillfed.io/dawiddutoit/custom-claude/pytest-configuration"},{"id":"dawiddutoit/custom-claude/pytest-adapter-integration-testing","name":"Pytest Adapter Integration Testing","publisher":"dawiddutoit/custom-claude","url":"https://skillfed.io/dawiddutoit/custom-claude/pytest-adapter-integration-testing"}],"title":"Pytest Mocking Strategy by dawiddutoit \u2014 SkillFed","use":{"when":["Pytest Mocking Strategy covers best practices for mocking that center on isolating dependencies during testing.","Pytest Mocking Strategy outlines best practices including autospec enforcement to prevent interface drift."]},"what":{"lead":"Pytest Mocking Strategy teaches when and how to mock dependencies in unit tests, covering autospec, AsyncMock, and what should never be mocked.","rest":"Learn a decision-driven framework for mocking in pytest that separates external boundaries from business logic. This skill covers autospec enforcement, async mock patterns, reusable mock factories, and a clear matrix for what to mock versus what to test directly. Master the golden rule\u2014mock external dependencies, test the unit in isolation\u2014to write tests that survive refactoring."}},"id":"dawiddutoit/custom-claude/pytest-mocking-strategy","install":{"mode":"external","repo":"https://github.com/dawiddutoit/custom-claude"},"links":{"html":"https://skillfed.io/dawiddutoit/custom-claude/pytest-mocking-strategy","md":"https://skillfed.io/dawiddutoit/custom-claude/pytest-mocking-strategy.md","repo":"https://github.com/dawiddutoit/custom-claude"},"meta":{"agents_supported":[],"first_seen":"2026-07-28","forks":0,"language":"Python","last_updated":"2026-01-26","license":null,"name":"Pytest Mocking Strategy","publisher":"dawiddutoit","stars":1},"relations":{"similar":[{"id":"dawiddutoit/custom-claude/pytest-application-layer-testing"},{"id":"dawiddutoit/custom-claude/pytest-type-safety"},{"id":"dawiddutoit/custom-claude/pytest-async-testing"},{"id":"dawiddutoit/custom-claude/pytest-configuration"},{"id":"dawiddutoit/custom-claude/pytest-adapter-integration-testing"},{"id":"dawiddutoit/custom-claude/test-setup-async"},{"id":"dawiddutoit/custom-claude/textual-test-fixtures"},{"id":"xobotyi/cc-foundry/pytest"},{"id":"majesticlabs-dev/majestic-marketplace/pytest-coder"},{"id":"xu-xiang/everything-claude-code-zh/python-testing"}]},"slug":{"owner":"dawiddutoit","repo":"custom-claude","skill":"pytest-mocking-strategy"},"version":"64b086c3"}
