pytest-best-practices

Guide pytest test writing with fixtures, parametrization, and mocking patterns.

10|17|Updated Feb 22, 2026
One-click install
npx skills add https://github.com/provectus/awos-recruitment --skill pytest-best-practices-provectus
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest-best-practices
Source: https://github.com/provectus/awos-recruitment/tree/main/registry/skills/pytest-best-practices
Command: npx skills add https://github.com/provectus/awos-recruitment --skill pytest-best-practices-provectus

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides expert guidance and patterns for writing high-quality, maintainable, and efficient pytest tests, improving the reliability of your software.

Core Features & Use Cases

  • Fixture Management: Learn best practices for creating, scoping, and managing fixtures.
  • Parametrization: Efficiently test multiple scenarios with pytest.mark.parametrize.
  • Mocking & Patching: Master techniques for isolating code and mocking dependencies.
  • Use Case: When writing tests for a new feature, use this Skill to ensure your tests are independent, cover edge cases, and effectively use fixtures and mocks for clarity and speed.

Quick Start

Use the pytest-best-practices skill to learn about fixture scopes and teardown patterns.

Frequently Asked Questions about pytest-best-practices

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

FAQPage Schema
What are the best practices for managing pytest fixtures and scopes?

Pytest fixtures provide a reusable way to set up and tear down test states. Best practices include choosing appropriate scopes like function or module, ensuring test independence, and utilizing teardown patterns to maintain robust and maintainable test suites.

How do I use parametrization to test multiple scenarios in pytest?

Parametrization in pytest allows you to run the same test function against multiple inputs. Using the parametrize mark, you can efficiently cover edge cases and various scenarios, reducing code duplication and improving test coverage.

What is the best way to isolate code and mock dependencies in pytest?

Mocking and patching in pytest isolates your code from external dependencies. Best practices involve replacing actual objects with mocks to ensure tests run quickly and reliably without unintended side effects, maintaining clear and isolated test environments.

Why are my pytest tests failing due to shared state and how do I fix it?

Shared state in pytest tests often causes failures due to execution order dependencies. Fix this by enforcing test independence through proper fixture scoping and teardown patterns, ensuring each test runs in a clean, isolated environment without relying on previous test outcomes.

What directory structure and naming conventions should I use for pytest?

A robust pytest directory structure separates tests from source code using clear naming conventions. Best practices include organizing tests logically and using consistent naming patterns to improve maintainability and ease of navigation across the test suite.