Get the FREE Ultimate OpenClaw Setup Guide →

python-testing

npx machina-cli add skill athola/claude-night-market/python-testing --openclaw
Files (1)
SKILL.md
3.6 KB

Python Testing Hub

Testing standards for pytest configuration, fixture management, and TDD implementation.

Table of Contents

  1. Quick Start
  2. When to Use
  3. Modules

Quick Start

  1. Dependencies: pip install pytest pytest-cov pytest-asyncio pytest-mock
  2. Configuration: Add the following to pyproject.toml:
    [tool.pytest.ini_options]
    testpaths = ["tests"]
    addopts = "--cov=src"
    
  3. Verification: Run pytest to confirm discovery of files matching test_*.py.

When To Use

  • Constructing unit and integration tests for Python 3.9+ projects.
  • Isolating external dependencies using pytest-mock or custom monkeypatching.
  • Validating asynchronous logic with pytest-asyncio markers and event loop management.
  • Configuring project-wide coverage thresholds and reporting.

When NOT To Use

  • Evaluating test quality - use pensive:test-review instead
  • Infrastructure test config - use leyline:pytest-config
  • Evaluating test quality - use pensive:test-review instead
  • Infrastructure test config - use leyline:pytest-config

Modules

This skill uses modular loading to manage the system prompt budget.

Core Implementation

  • See modules/unit-testing.md - AAA (Arrange-Act-Assert) pattern, basic test structure, and exception validation.
  • See modules/fixtures-and-mocking.md - Request-scoped fixtures, parameterization, and boundary mocking.
  • See modules/async-testing.md - Coroutine testing, async fixtures, and concurrency validation.

Infrastructure & Workflow

  • See modules/test-infrastructure.md - Directory standards, conftest.py management, and coverage tools.
  • See modules/testing-workflows.md - Local execution patterns and GitHub Actions integration.

Standards

  • See modules/test-quality.md - Identification of common anti-patterns like broad exception catching or shared state between tests.

Exit Criteria

  • Tests implement the AAA pattern.
  • Coverage reaches the 80% project minimum.
  • Individual tests are independent and do not rely on execution order.
  • Fixtures are scoped appropriately (function, class, or session) to prevent side effects.
  • Mocking is restricted to external system boundaries.

Troubleshooting

  • Test Discovery: Verify filenames match the test_*.py pattern. Use pytest --collect-only to debug discovery paths.
  • Import Errors: Ensure the local source directory is in the path, typically by installing in editable mode with pip install -e ..
  • Async Failures: Confirm that pytest-asyncio is installed and that async tests use the @pytest.mark.asyncio decorator or corresponding auto-mode configuration.

Source

git clone https://github.com/athola/claude-night-market/blob/master/plugins/parseltongue/skills/python-testing/SKILL.mdView on GitHub

Overview

Provides practical guidance for building Python test suites, including unit and integration tests, TDD practices, fixture management, async testing, and mocking. It explains how to configure pytest, enforce coverage, and integrate tests into CI/CD to maintain quality.

How This Skill Works

This skill organizes guidance into modules (unit-testing, fixtures-and-mocking, async-testing, etc.) with concrete commands, configuration snippets, and patterns like AAA. It references tools such as test-analyzer, coverage-reporter, and test-runner to support implementation and measurement.

When to Use It

  • Constructing unit and integration tests for Python 3.9+ projects.
  • Isolating external dependencies using pytest-mock or custom monkeypatching.
  • Validating asynchronous logic with pytest-asyncio markers and event loop management.
  • Configuring project-wide coverage thresholds and reporting.
  • Setting up test suites and CI/CD workflows to run tests automatically.

Quick Start

  1. Step 1: Dependencies: `pip install pytest pytest-cov pytest-asyncio pytest-mock`
  2. Step 2: Configuration: Add the following to `pyproject.toml`: ```toml [tool.pytest.ini_options] testpaths = ["tests"] addopts = "--cov=src" ```
  3. Step 3: Verification: Run `pytest` to confirm discovery of files matching `test_*.py`.

Best Practices

  • AAA pattern: Arrange-Act-Assert in every test.
  • Isolate external dependencies with mocks within external boundaries.
  • Scope fixtures (function, class, or session) to prevent shared state.
  • Ensure tests are independent of execution order.
  • Aim for 80% project-wide coverage and verify with reports.

Example Use Cases

  • Unit tests with fixtures for setup and teardown using pytest fixtures.
  • Parametrized tests with pytest.mark.parametrize to cover multiple inputs.
  • Async tests with pytest-asyncio and async fixtures to validate concurrency.
  • Mocked external calls using pytest-mock to isolate network I/O.
  • CI workflow: run pytest with coverage reporting and enforce a threshold.

Frequently Asked Questions

Add this skill to your agents

Related Skills

precommit-setup

athola/claude-night-market

Configure three-layer pre-commit system with linting, type checking, and testing hooks. Use for quality gate setup and code standards. Skip if pre-commit is optimally configured.

ab-test-setup

coreyhaines31/marketingskills

When the user wants to plan, design, or implement an A/B test or experiment. Also use when the user mentions "A/B test," "split test," "experiment," "test this change," "variant copy," "multivariate test," "hypothesis," "should I test this," "which version is better," "test two versions," "statistical significance," or "how long should I run this test." Use this whenever someone is comparing two approaches and wants to measure which performs better. For tracking implementation, see analytics-tracking. For page-level conversion optimization, see page-cro.

Playwright Browser Automation

jpulido240-svg/playwright-skill

Complete browser automation with Playwright. Auto-detects dev servers, writes clean test scripts to /tmp. Test pages, fill forms, take screenshots, check responsive design, validate UX, test login flows, check links, automate any browser task. Use when user wants to test websites, automate browser interactions, validate web functionality, or perform any browser-based testing.

workflow-setup

athola/claude-night-market

Configure GitHub Actions CI/CD workflows for automated testing, linting, and deployment. Use for CI/CD setup and quality automation. Skip if CI/CD configured or using different platform.

RubyCritic Code Quality Analysis

esparkman/claude-rubycritic-skill

Analyze Ruby and Rails code quality with RubyCritic. Identifies code smells, complexity issues, and refactoring opportunities. Provides detailed metrics, scores files A-F, compares branches, and prioritizes high-churn problem areas. Use when analyzing Ruby code quality, reviewing PRs, or identifying technical debt.

subagent-testing

athola/claude-night-market

TDD-style testing methodology for skills using fresh subagent instances

Sponsor this space

Reach thousands of developers