python-testing-general

Provide pytest standards for writing isolated, maintainable Python tests.

13|2|Updated Feb 28, 2026
One-click install
npx skills add https://github.com/amrahman90/python-expert-agent --skill python-testing-general
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-testing-general
Source: https://github.com/amrahman90/python-expert-agent/tree/main/.opencode/skills/python-testing-general
Command: npx skills add https://github.com/amrahman90/python-expert-agent --skill python-testing-general

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

This Skill provides comprehensive guidance and best practices for writing reliable, isolated, and maintainable tests in Python projects using pytest, addressing the challenges of ensuring code quality and preventing regressions.

Core Features & Use Cases

  • Test Structure and Conventions: Learn standard naming, the AAA pattern, and how to organize test files.
  • Test Isolation: Techniques for managing working directories, temporary files, and script path discovery.
  • Fixtures and Parametrization: Efficiently manage test setup, teardown, and data variations.
  • Mocking: Strategies for isolating code under test from external dependencies.
  • Assertions: Best practices for verifying test outcomes, including exceptions and approximate values.
  • Async Testing: How to test asynchronous Python code effectively.
  • Use Case: When developing a new feature in a Python application, use this Skill to ensure all new code is covered by well-structured, isolated, and maintainable pytest tests, including mocking external API calls and database interactions.

Quick Start

Use the python-testing-general skill to write pytest tests for the src/services/user.py file, including unit tests, mocking the database, and testing edge cases.

Frequently Asked Questions about python-testing-general

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

FAQPage Schema
How do I write isolated pytest tests for Python applications?

To write isolated pytest tests, use fixtures for setup and teardown, manage temporary files, and employ mocking to separate code from external dependencies like databases. This approach ensures tests run reliably without side effects.

What is the best way to mock external dependencies in pytest?

The best way to mock external dependencies in pytest is by using strategies that isolate the code under test from external systems like APIs and databases. This involves replacing actual calls with mock objects to ensure tests remain fast, reliable, and isolated.

How do I parametrize tests in pytest to cover data variations?

Parametrizing tests in pytest allows you to run the same test function against multiple data sets. By applying parametrization patterns, you can efficiently manage data variations and reduce code duplication while ensuring broad test coverage.

Can I use pytest to test asynchronous Python code?

Yes, pytest can be used to test asynchronous Python code effectively. The skill provides specific patterns and best practices for async testing scenarios, ensuring your async functions are properly validated and integrated into your test suite.

What is the AAA pattern in pytest test structure?

The AAA pattern in pytest test structure stands for Arrange, Act, and Assert. It provides a standard convention for organizing test files and naming, ensuring tests are readable, maintainable, and clearly separated into setup, execution, and verification phases.

How do I verify exceptions and approximate values in pytest assertions?

Verifying exceptions and approximate values in pytest assertions requires using specific assertion best practices. This includes checking that expected exceptions are raised and using approximate comparisons for floating-point numbers to ensure accurate test outcomes.