pytest-fixtures

Configure Pytest fixtures, conftest files, and parametrize decorators for test setup.

1|Updated Jun 18, 2025
One-click install
npx skills add https://github.com/knopki/dotfiles --skill pytest-fixtures-knopki
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest-fixtures
Source: https://github.com/knopki/dotfiles/tree/main/home/private_dot_config/opencode/skills/pytest-fixtures
Command: npx skills add https://github.com/knopki/dotfiles --skill pytest-fixtures-knopki

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill helps you effectively manage and leverage Pytest fixtures, conftest files, and decorators for comprehensive and efficient test setup in Python projects.

Core Features & Use Cases

  • Fixture Management: Understand and implement fixtures for setup, teardown, and dependency injection.
  • Conftest Files: Learn how to organize fixtures and hooks in conftest.py for broader scope.
  • Parametrization: Utilize @pytest.mark.parametrize for efficient test case generation.
  • Fixture Scopes: Grasp the different scopes (function, class, module, session) for optimal resource management.
  • Use Case: When developing a complex Python application, use this Skill to ensure all your tests have reliable and isolated environments, reducing flaky tests and improving development speed.

Quick Start

Use the pytest-fixtures skill to set up a basic fixture for database connection in your test suite.

Frequently Asked Questions about pytest-fixtures

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use pytest fixtures for test setup and teardown in Python?

Pytest fixtures provide a reliable way to manage setup, teardown, and dependency injection. You define reusable functions and apply them to tests, ensuring isolated and consistent environments that reduce flaky results.

What is a conftest.py file and when do I need it for pytest fixtures?

A conftest.py file organizes fixtures and hooks for broader scope across multiple test modules. You need it when sharing setup logic across a directory, allowing you to manage dependencies without repeating imports in every test file.

How do I parametrize pytest tests using decorators?

You can parametrize pytest tests by applying the @pytest.mark.parametrize decorator to a test function. This allows efficient test case generation by feeding multiple data sets into a single test, reducing redundant code.

What are the different pytest fixture scopes and how do I choose?

Pytest fixture scopes include function, class, module, and session. You choose a scope based on resource management needs, setting broader scopes like session for expensive resources to optimize execution speed and reduce overhead.

Can I use pytest fixtures to establish a database connection for my test suite?

Yes, you can set up a basic fixture for database connections in your test suite. By managing the connection within a fixture, you ensure reliable environments and proper teardown, preventing database locks across test runs.

Why are my pytest tests flaky and how can fixture scopes help?

Flaky tests often stem from improper resource management or shared state. By grasping and applying the correct fixture scopes, you ensure optimal resource isolation and cleanup, which stabilizes your test environments.