testing

Standardize Python testing practices with Pytest, fixtures, mocking, and coverage analysis.

1|Updated Dec 10, 2025
One-click install
npx skills add https://github.com/markus41/lobbi-design-system --skill testing-markus41
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing
Source: https://github.com/markus41/lobbi-design-system/tree/main/.claude/skills/testing
Command: npx skills add https://github.com/markus41/lobbi-design-system --skill testing-markus41

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pytest, pytest-cov, pytest-xdist.

What problem does it solve?

This Skill provides comprehensive patterns and best practices for writing effective tests, managing test data, and ensuring high code coverage, ultimately improving software quality and reliability.

Core Features & Use Cases

  • Pytest Integration: Run tests, manage fixtures, and configure coverage analysis with Pytest.
  • Mocking & Parametrization: Use unittest.mock for isolating dependencies and parametrize tests for various scenarios.
  • Test Structure: Organize unit and integration tests for clarity and maintainability.
  • Use Case: Write unit tests for a Python function using Pytest, including fixtures for database setup and mocking external API calls to ensure all components work as expected.

Quick Start

Write a Pytest unit test for a function 'uppercase(text)' that asserts it converts input to uppercase.

Frequently Asked Questions about testing

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

FAQPage Schema
How do I write unit tests for Python functions with Pytest?

Unit tests with Pytest involve writing test functions that assert expected behavior. Create a test file, import your function, and use `assert` statements to verify outputs. Pytest automatically discovers and runs test files matching the `test_*.py` naming convention.

What's the best way to ensure code coverage in Python tests?

Code coverage measures how much of your codebase tests exercise. Use pytest-cov to generate coverage reports and identify untested lines. Run `pytest --cov` to see coverage percentages and locate gaps in your test suite.

How do I mock external API calls in Pytest tests?

Mocking isolates tests from external dependencies using `unittest.mock`. Import `patch` or `Mock`, replace the API call in your test, and verify the mock was called correctly. This ensures tests run reliably without hitting real services.

Can I run the same test with multiple input values?

Yes, Pytest's parametrization feature lets you run one test function with different inputs. Use `@pytest.mark.parametrize` to define multiple test cases, reducing code duplication and improving test coverage across scenarios.

How do I organize unit and integration tests in a Python project?

Organize tests in a dedicated `tests/` directory mirroring your project structure. Separate unit tests from integration tests using subdirectories or naming conventions. Use Pytest fixtures to manage test data and setup, improving maintainability and clarity.

What's the difference between unit tests and integration tests?

Unit tests verify individual functions in isolation using mocks for dependencies. Integration tests verify multiple components work together with real or semi-real interactions. Both are essential; use unit tests for speed and integration tests for confidence in system behavior.