pytest

Write pytest tests with fixtures, mocking, parametrization, and markers.

2|Updated Jun 11, 2024
One-click install
npx skills add https://github.com/gutierrezp22/administracion-departamentos --skill pytest-gutierrezp22
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest
Source: https://github.com/gutierrezp22/administracion-departamentos/tree/main/.cursor/skills/pytest
Command: npx skills add https://github.com/gutierrezp22/administracion-departamentos --skill pytest-gutierrezp22

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill streamlines the process of writing robust and efficient tests for Python applications, ensuring code quality and reliability.

Core Features & Use Cases

  • Test Structure: Provides examples for basic test cases, user creation, and validation.
  • Fixtures: Demonstrates how to use fixtures for setup/teardown and dependency injection, including different scopes (module, class, session).
  • Mocking: Shows how to mock external dependencies like API clients and database sessions for isolated testing.
  • Parametrization: Illustrates how to run the same test with multiple data sets for comprehensive coverage.
  • Markers: Explains how to use markers for categorizing tests (e.g., slow, integration) and conditional skipping.
  • Async Tests: Covers testing asynchronous Python functions.
  • Command-line Usage: Lists common pytest commands for running, filtering, and analyzing tests.

Quick Start

Use the pytest skill to generate a basic test structure for a Python class.

Frequently Asked Questions about pytest

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

FAQPage Schema
How do I structure basic Python tests using pytest?

To structure basic Python tests using pytest, you write functions prefixed with test_ and use assert statements for validation. This skill provides patterns for basic test cases, user creation, and validation to ensure code quality.

How do I use pytest fixtures for setup and dependency injection?

Pytest fixtures handle setup, teardown, and dependency injection by decorating functions with @pytest.fixture. This skill demonstrates using different fixture scopes including module, class, and session for maintainable test suites.

How do I mock external dependencies like API clients in Python tests?

You mock external dependencies like API clients and database sessions to achieve isolated testing. This skill shows specific mocking patterns to replace external calls during test execution.

Can I run the same pytest test with multiple data sets?

Yes, you can run the same test with multiple data sets using parametrization. This skill illustrates how to use the parametrize marker to execute tests comprehensively across various inputs.

How do I categorize and conditionally skip Python tests with markers?

You categorize and conditionally skip Python tests using pytest markers. This skill explains how to label tests as slow or integration and apply conditional skipping for targeted test runs.

Does pytest support testing asynchronous Python functions?

Yes, pytest supports testing asynchronous Python functions. This skill covers specific patterns and examples for writing effective tests for async scenarios.