Setup Pytest Fixtures
Setup Pytest Fixtures guides you through building reusable test fixtures with factory patterns, async support, and proper conftest organization. Learn to structure fixtures across centralized utilities and layer-specific configurations, then apply them across your test suite.
Setup Pytest Fixtures teaches you to create reusable pytest fixtures with factory patterns and async support.
AI-generated summary based on this skill's SKILL.md
Install
dawiddutoit/custom-claude/setup-pytest-fixtures · repository language: Python
git clone https://github.com/dawiddutoit/custom-claude
cp -r custom-claude ~/.claude/skills/setup-pytest-fixturesgenerated, unverified - the skill's exact subdirectory could not be determined; check the repository on GitHub
npx skillfed install dawiddutoit/custom-claude/setup-pytest-fixturesFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How do I create pytest fixtures?
Setup Pytest Fixtures teaches you to create reusable test fixtures by decorating functions with @pytest.fixture. Define your fixture function in a test file or conftest.py, then pass the fixture name as a parameter to any test that needs it. Fixtures can return data, set up resources, or perform initialization—pytest automatically injects them into your tests.
What are pytest fixture best practices?
Setup Pytest Fixtures covers best practices including organizing fixtures in conftest.py for centralized reuse, using factory patterns for flexible test data, applying proper scopes (function, class, module, session), and implementing teardown logic with yield statements. Structure fixtures across layer-specific configurations and avoid tight coupling between fixtures and tests.
How do I configure pytest fixtures for test initialization and teardown?
Setup Pytest Fixtures shows you to use yield in fixture functions to separate setup from teardown code. Code before yield runs before the test; code after runs after. Alternatively, use request.addfinalizer() for cleanup. Set fixture scope with @pytest.fixture(scope='...') to control when setup and teardown execute across your test suite.
Setting up test fixtures pytest—where do I start?
Setup Pytest Fixtures guides you to begin by creating a conftest.py file in your test directory to centralize fixture definitions. Write fixture functions decorated with @pytest.fixture, then reference them by name in your test functions. Start with function-scoped fixtures for isolated tests, then advance to module or session scopes as your suite grows.
Can Setup Pytest Fixtures help with async test fixtures?
Setup Pytest Fixtures includes async support through pytest-asyncio. Define async fixtures with async def and @pytest.fixture, then use them in async test functions. This enables testing asynchronous code with proper setup and teardown, maintaining the same fixture patterns and scoping rules as synchronous fixtures.
How do I reuse pytest fixtures across multiple test files?
Setup Pytest Fixtures teaches fixture reuse by placing shared fixtures in conftest.py at your project root or test directory. Pytest automatically discovers and makes these fixtures available to all tests in that directory and subdirectories. Use this centralized approach to build a library of common fixtures for database connections, API clients, and test data factories.