python-testing

Guide Python testing with pytest, TDD, fixtures, mocking, and async tests.

10|3|Updated Apr 3, 2012
One-click install
npx skills add https://github.com/liuerfire/dotfiles --skill python-testing-liuerfire
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-testing
Source: https://github.com/liuerfire/dotfiles/tree/main/agentic/skills/python-testing
Command: npx skills add https://github.com/liuerfire/dotfiles --skill python-testing-liuerfire

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides comprehensive strategies and best practices for writing robust, maintainable, and efficient tests for Python applications, ensuring code quality and reliability.

Core Features & Use Cases

  • Test-Driven Development (TDD): Guides users through the red-green-refactor cycle.
  • Pytest Fundamentals: Covers basic test structure, assertions, fixtures, and parametrization.
  • Advanced Techniques: Includes mocking, patching, testing async code, and exception handling.
  • Use Case: When developing a new Python feature, use this Skill to learn how to write effective unit tests using pytest, ensuring the feature works as expected and is easily testable.

Quick Start

Activate this skill to learn how to write a basic pytest test case for a Python function.

Frequently Asked Questions about python-testing

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

FAQPage Schema
How do I write a pytest test case for a Python function?

To write a pytest test case, define a Python function prefixed with test_ and use standard assert statements to validate outputs. This Skill guides you through structuring tests, using fixtures, and parametrizing inputs for comprehensive coverage.

What's the best way to mock external API calls in pytest?

The best way to mock external API calls in pytest is using unittest.mock to patch requests and responses. This Skill covers mocking techniques and patching dependencies to isolate API and database testing patterns effectively.

How does test-driven development work with pytest?

Test-driven development with pytest follows the red-green-refactor cycle: write a failing test, write code to pass it, then refactor. This Skill provides strategies for implementing TDD workflows to ensure robust Python application quality.

Can I test asynchronous Python code with pytest?

Yes, you can test asynchronous Python code with pytest using the pytest-asyncio plugin. This Skill explains how to configure and write async test cases to validate your asynchronous functions and coroutines.

How do I use pytest fixtures to set up and tear down database tests?

Pytest fixtures provide a reliable way to set up and tear down database states by injecting reusable objects into test functions. This Skill details fixture configuration and common testing patterns for database operations.

How do I parametrize tests in pytest to check multiple inputs?

Parametrizing tests in pytest allows you to run a single test function against multiple input sets using the @pytest.mark.parametrize decorator. This Skill covers execution strategies for efficient parametrized testing.