Agent skill

Python Testing

by Yikai-Liao in Yikai-Liao/symusic

Write and organize tests for scientific Python packages using pytest.

MITAuto-check passedTesting & QA

Install Python Testing

skills CLI
$ npx skills add Yikai-Liao/symusic --skill python-testing -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install Yikai-Liao/symusic python-testing --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/Yikai-Liao/symusic.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/python-testing .claude/skills/python-testing && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
python-testing
GitHub stars
189
Token cost
~3.3k tokens
SKILL.md length
1,069 words
Files
7 (incl. references, assets)
Skills in repo
11
Repo updated
First seen
Licence
MIT

At a glance

Write and organize tests for scientific Python packages using pytest.

  • Works in 3 steps: Why pytest for Scientific Python → Test Structure and Organization → pytest Configuration
  • Tasks that involve Unit testing
  • SKILL.md covers Quick Reference Card, When to Use This Skill, Core Concepts and Testing Principles, plus 10 more sections
  • Runs Python scripts from its folder; calls pytest and pip

What it does

Python Testing is an agent skill from Yikai-Liao/symusic. Write and organize tests for scientific Python packages using pytest. Covers fixtures, parametrization, numerical testing with NumPy utilities, property-based testing with Hypothesis, and CI integration.

Its SKILL.md is about 3.3k tokens, which your agent loads only when the skill is triggered. The skill folder holds 8 other files, including reference files and assets (for example `assets/conftest-example.py`, `assets/github-actions-tests.yml` and `references/common-pitfalls.md`).

It sits in Testing & QA, covering Unit testing. It works with Python, pytest and NumPy. The repository describes itself as: A swift and unified toolkit for symbolic music processing. The licence is MIT.

When your agent uses it

  • Tasks that involve Unit testing

Example prompts

  • “/python-testing”

Requirements

  • Python 3

Workflow steps

3 steps, taken from the step headings in SKILL.md.

  1. Why pytest for Scientific Python
  2. Test Structure and Organization
  3. pytest Configuration

What it can do on your machine

Read from SKILL.md and the folder at commit 3cdd0ee. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships script files (Python), which the agent can run.

    Shell commands in SKILL.md call:

    • pytest
    • pip

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • learn.scientific-python.org
    • docs.pytest.org
    • pytest-cov.readthedocs.io
    • pytest-mock.readthedocs.io
    • hypothesis.readthedocs.io
    • numpy.org
    • docs.python-guide.org

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Python Testing loads about 3.3k tokens when it runs, and up to ~9.7k if it reads all its reference files. Until then it costs about 55 tokens; SKILL.md has 1,069 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~55
When it runs · the whole SKILL.md, loaded when a task matches
~3.3k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~9.7k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from Yikai-Liao/symusic at commit 3cdd0ee, republished under its MIT licence (© Yikai-Liao). 1,069 words, ~3,324 tokens.

Download SKILL.mdSave it as .claude/skills/python-testing/SKILL.md (or your agent's skills folder). This skill also uses 6 other files; get the full folder from GitHub.
name
python-testing
description
Write and organize tests for scientific Python packages using pytest. Covers fixtures, parametrization, numerical testing with NumPy utilities, property-based testing with Hypothesis, and CI integration.
metadata.assets
assets/conftest-example.py, assets/github-actions-tests.yml, assets/pyproject-pytest.toml
metadata.references
references/common-pitfalls.md, references/scientific-patterns.md, references/test-patterns.md

Scientific Python Testing with pytest

A comprehensive guide to writing effective tests for scientific Python packages using pytest, following the Scientific Python Community guidelines and testing tutorial. This skill focuses on modern testing patterns, fixtures, parametrization, and best practices specific to scientific computing.

Quick Reference Card

Common Testing Tasks - Quick Decisions:

python
# 1. Basic test → Use simple assert
def test_function():
    assert result == expected

# 2. Floating-point comparison → Use approx
from pytest import approx
assert result == approx(0.333, rel=1e-6)

# 3. Testing exceptions → Use pytest.raises
with pytest.raises(ValueError, match="must be positive"):
    function(-1)

# 4. Multiple inputs → Use parametrize
@pytest.mark.parametrize("input,expected", [(1,1), (2,4), (3,9)])
def test_square(input, expected):
    assert input**2 == expected

# 5. Reusable setup → Use fixture
@pytest.fixture
def sample_data():
    return np.array([1, 2, 3, 4, 5])

# 6. NumPy arrays → Use approx or numpy.testing
assert np.mean(data) == approx(3.0)

Decision Tree:

  • Need multiple test cases with same logic? → Parametrize
  • Need reusable test data/setup? → Fixture
  • Testing floating-point results? → pytest.approx
  • Testing exceptions/warnings? → pytest.raises / pytest.warns
  • Complex numerical arrays? → numpy.testing.assert_allclose
  • Organizing by speed? → Markers and separate directories

When to Use This Skill

  • Writing tests for scientific Python packages and libraries
  • Testing numerical algorithms and scientific computations
  • Setting up test infrastructure for research software
  • Implementing continuous integration for scientific code
  • Testing data analysis pipelines and workflows
  • Validating scientific simulations and models
  • Ensuring reproducibility and correctness of research code
  • Testing code that uses NumPy, SciPy, Pandas, and other scientific libraries

Core Concepts

1. Why pytest for Scientific Python

pytest is the de facto standard for testing Python packages because it:

  • Simple syntax: Just use Python's assert statement
  • Detailed reporting: Clear, informative failure messages
  • Powerful features: Fixtures, parametrization, marks, plugins
  • Scientific ecosystem: Native support for NumPy arrays, approximate comparisons
  • Community standard: Used by NumPy, SciPy, Pandas, scikit-learn, and more
2. Test Structure and Organization

Standard test directory layout:

text
my-package/
├── src/
│   └── my_package/
│       ├── __init__.py
│       ├── analysis.py
│       └── utils.py
├── tests/
│   ├── conftest.py
│   ├── test_analysis.py
│   └── test_utils.py
└── pyproject.toml

Key principles:

  • Tests directory separate from source code (alongside src/)
  • Test files named test_*.py (pytest discovery)
  • Test functions named test_* (pytest discovery)
  • No __init__.py in tests directory (avoid importability issues)
  • Test against installed package, not local source
3. pytest Configuration

See assets/pyproject-pytest.toml for a complete pytest configuration example.

Basic configuration in pyproject.toml:

toml
[tool.pytest.ini_options]
minversion = "7.0"
addopts = [
    "-ra",              # Show summary of all test outcomes
    "--showlocals",     # Show local variables in tracebacks
    "--strict-markers", # Error on undefined markers
    "--strict-config",  # Error on config issues
]
testpaths = ["tests"]

Testing Principles

Following the Scientific Python testing recommendations, effective testing provides multiple benefits and should follow key principles:

Advantages of Testing
  • Trustworthy code: Well-tested code behaves as expected and can be relied upon
  • Living documentation: Tests communicate intent and expected behavior, validated with each run
  • Preventing failure: Tests protect against implementation errors and unexpected dependency changes
  • Confidence when making changes: Thorough test suites enable adding features, fixing bugs, and refactoring with confidence
Fundamental Principles

1. Any test case is better than none

When in doubt, write the test that makes sense at the time:

  • Test critical behaviors, features, and logic
  • Write clear, expressive, well-documented tests
  • Tests are documentation of developer intentions
  • Good tests make it clear what they are testing and how

Don't get bogged down in taxonomy when learning—focus on writing tests that work.

2. As long as that test is correct

It's surprisingly easy to write tests that pass when they should fail:

  • Check that your test fails when it should: Deliberately break the code and verify the test fails
  • Keep it simple: Excessive mocks and fixtures make it difficult to know what's being tested
  • Test one thing at a time: A single test should test a single behavior

3. Start with Public Interface Tests

Begin by testing from the perspective of a user:

  • Test code as users will interact with it
  • Keep tests simple and readable for documentation purposes
  • Focus on supported use cases
  • Avoid testing private attributes
  • Minimize use of mocks/patches

4. Organize Tests into Suites

Divide tests by type and execution time for efficiency:

  • Unit tests: Fast, isolated tests of individual components
  • Integration tests: Tests of component interactions and dependencies
  • End-to-end tests: Complete workflow testing

Benefits:

  • Run relevant tests quickly and frequently
  • "Fail fast" by running fast suites first
  • Easier to read and reason about
  • Avoid false positives from expected external failures
Outside-In Testing Approach

The recommended approach is outside-in, starting from the user's perspective:

  1. Public Interface Tests: Test from user perspective, focusing on behavior and features
  2. Integration Tests: Test that components work together and with dependencies
  3. Unit Tests: Test individual units in isolation, optimized for speed

This approach ensures you're building the right thing before optimizing implementation details.

Quick Start

Minimal Test Example
python
# tests/test_basic.py

def test_simple_math():
    """Test basic arithmetic."""
    assert 4 == 2**2

def test_string_operations():
    """Test string methods."""
    result = "hello world".upper()
    assert result == "HELLO WORLD"
    assert "HELLO" in result
Scientific Test Example
python
# tests/test_scientific.py
import numpy as np
from pytest import approx

from my_package.analysis import compute_mean, fit_linear

def test_compute_mean():
    """Test mean calculation."""
    data = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
    result = compute_mean(data)
    assert result == approx(3.0)

def test_fit_linear():
    """Test linear regression."""
    x = np.array([0, 1, 2, 3, 4])
    y = np.array([0, 2, 4, 6, 8])
    slope, intercept = fit_linear(x, y)

    assert slope == approx(2.0)
    assert intercept == approx(0.0)
Show full SKILL.md (429 more words)Show less

Testing Patterns

See references/test-patterns.md for detailed patterns including:

  • Writing simple, focused tests
  • Testing for failures
  • Approximate comparisons
  • Using fixtures
  • Parametrized tests
  • Test organization with markers
  • Mocking and monkeypatching
  • Testing against installed version
  • Import best practices

Scientific Python Testing Patterns

See references/scientific-patterns.md for scientific-specific patterns:

  • Testing numerical algorithms
  • Testing with different NumPy dtypes
  • Testing random/stochastic code
  • Testing data pipelines
  • Property-based testing with Hypothesis

Running pytest

Basic Usage
bash
# Run all tests
pytest

# Run specific file
pytest tests/test_analysis.py

# Run specific test
pytest tests/test_analysis.py::test_mean

# Run tests matching pattern
pytest -k "mean or median"

# Verbose output
pytest -v

# Show local variables in failures
pytest -l  # or --showlocals

# Stop at first failure
pytest -x

# Show stdout/stderr
pytest -s
Debugging Tests
bash
# Drop into debugger on failure
pytest --pdb

# Drop into debugger at start of each test
pytest --trace

# Run last failed tests
pytest --lf

# Run failed tests first, then rest
pytest --ff

# Show which tests would be run (dry run)
pytest --collect-only
Coverage
bash
# Install pytest-cov
pip install pytest-cov

# Run with coverage
pytest --cov=my_package

# With coverage report
pytest --cov=my_package --cov-report=html

# With missing lines
pytest --cov=my_package --cov-report=term-missing

# Fail if coverage below threshold
pytest --cov=my_package --cov-fail-under=90

See assets/pyproject-pytest.toml for complete coverage configuration.

File Templates and Examples

Ready-to-use templates are available in the assets/ directory:

Common Pitfalls and Solutions

See references/common-pitfalls.md for solutions to:

  • Testing implementation instead of behavior
  • Non-deterministic tests
  • Exact floating-point comparisons
  • Testing too much in one test

Testing Checklist

  • Tests are in tests/ directory separate from source
  • Test files named test_*.py
  • Test functions named test_*
  • Tests run against installed package (use src/ layout)
  • pytest configured in pyproject.toml
  • Using pytest.approx for floating-point comparisons
  • Tests check exceptions with pytest.raises
  • Tests check warnings with pytest.warns
  • Parametrized tests for multiple inputs
  • Fixtures for reusable setup
  • Markers used for test organization
  • Random tests use fixed seeds
  • Tests are independent (can run in any order)
  • Each test focuses on one behavior
  • Coverage > 80% (preferably > 90%)
  • All tests pass before committing
  • Slow tests marked with @pytest.mark.slow
  • Integration tests marked appropriately
  • CI configured to run tests automatically

Continuous Integration

See assets/github-actions-tests.yml for a complete GitHub Actions workflow example.

Resources

Summary

Testing scientific Python code with pytest, following Scientific Python community principles, provides:

  1. Confidence: Know your code works correctly
  2. Reproducibility: Ensure consistent behavior across environments
  3. Documentation: Tests show how code should be used and communicate developer intent
  4. Refactoring safety: Change code without breaking functionality
  5. Regression prevention: Catch bugs before they reach users
  6. Scientific rigor: Validate numerical accuracy and physical correctness

Key testing principles:

  • Start with public interface tests from the user's perspective
  • Organize tests into suites (unit, integration, e2e) by type and speed
  • Follow outside-in approach: public interface → integration → unit tests
  • Keep tests simple, focused, and independent
  • Test behavior rather than implementation
  • Use pytest's powerful features (fixtures, parametrization, markers) effectively
  • Always verify tests fail when they should to avoid false confidence

Remember: Any test is better than none, but well-organized tests following these principles create trustworthy, maintainable scientific software that the community can rely on.

© Yikai-Liao, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 6 other files (references, assets) in .agents/skills/python-testing of Yikai-Liao/symusic.

  • SKILL.md
  • assets/conftest-example.py
  • assets/github-actions-tests.yml
  • assets/pyproject-pytest.toml
  • references/common-pitfalls.md
  • references/scientific-patterns.md
  • references/test-patterns.md

Open the folder on GitHubat commit 3cdd0ee

Compare with similar skills

Python Testing next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Python Testing compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Python Testing this skillYikai-Liao/symusic189—~3.3kAutomated safety check: PassMIT
Adk Verify Snippetsgoogle/adk-python22k—~1.4kAutomated safety check: PassApache-2.0
Hermetic Python Unit TestsdimensionalOS/dimos4.6k—~1.4kAutomated safety check: PassCustom licence
ONNX Runtime Test Runnermicrosoft/onnxruntime22k—~1.8kAutomated safety check: PassMIT
Simple Modern Uvjlevy/simple-modern-uv301—~1.9kAutomated safety check: PassMIT
Test Coverage Reviewareed1192/finance-news-aggregator149—~2.6kAutomated safety check: PassMIT

Similar skills

  • Adk Verify Snippets

    google/adk-python

    Official

    Checks that every Python code block in a Markdown file actually compiles and runs, by extracting each block to a temporary file, executing it in an isolated subprocess, and writing a pass/fail…

    22k GitHub stars~1.4k tokensUpdated today
    Testing & QAAuto-check passed
  • Hermetic Python Unit Tests

    dimensionalOS/dimos

    Rules for writing, fixing and reviewing pytest unit tests that are hermetic: behavior-focused, deterministic, isolated and cheap to run.

    4.6k GitHub stars~1.4k tokensUpdated today
    Testing & QAAuto-check passed
  • ONNX Runtime Test Runner

    microsoft/onnxruntime

    Official

    Runs and debugs ONNX Runtime tests: Google Test executables for C++ and unittest or pytest for Python, with filters and build-directory guidance.

    22k GitHub stars~1.8k tokensUpdated today
    Testing & QAAuto-check passed
  • Simple Modern Uv

    jlevy/simple-modern-uv

    Start, selectively modernize, fully migrate, or update Python projects using simple-modern-uv practices: uv, ruff, BasedPyright, pytest, GitHub Actions CI, and tag-driven PyPI publishing.

    301 GitHub stars~1.9k tokensUpdated 1 mo ago
    Testing & QAAuto-check passed
  • Test Coverage Review

    areed1192/finance-news-aggregator

    Audit, plan, write, and verify unit tests for Python projects using pytest.

    149 GitHub stars~2.6k tokensUpdated 5 mo ago
    Testing & QAAuto-check passed
  • Official

    Runs the ONNX Runtime transformers Python tests against a GPU wheel and proves the cuDNN flash attention path was used rather than a silent fallback.

    22k GitHub stars~2.9k tokensUpdated today
    Testing & QAAuto-check passed

More from Yikai-Liao/symusic

All 11 skills in this repo
  • Uv Package Manager

    Yikai-Liao/symusic

    Master the uv package manager for fast Python dependency management, virtual environments, and modern Python project workflows.

    189 GitHub starsUsed in 15 repos~4k tokens
    Auto-check: notes
  • Code Reviewer

    Yikai-Liao/symusic

    Analyzes code diffs and files to identify bugs, security vulnerabilities (SQL injection, XSS, insecure deserialization), code smells, N+1 queries, naming issues, and architectural concerns, then…

    189 GitHub starsUsed in 1 repo~1.3k tokens
    Auto-check passed
  • Cpp Pro

    Yikai-Liao/symusic

    Writes, optimizes, and debugs C++ applications using modern C++20/23 features, template metaprogramming, and high-performance systems techniques.

    189 GitHub starsUsed in 1 repo~1.1k tokens
    Auto-check passed
  • Python Packaging

    Yikai-Liao/symusic

    Create and publish distributable scientific Python packages following Scientific Python community best practices.

    189 GitHub stars~2.3k tokensUpdated 1 mo ago
    Auto-check passed
  • Debugging Wizard

    Yikai-Liao/symusic

    Parses error messages, traces execution flow through stack traces, correlates log entries to identify failure points, and applies systematic hypothesis-driven methodology to isolate and resolve bugs.

    189 GitHub starsUsed in 1 repo~909 tokens
    Auto-check passed
  • Devops Engineer

    Yikai-Liao/symusic

    Creates Dockerfiles, configures CI/CD pipelines, writes Kubernetes manifests, and generates Terraform/Pulumi infrastructure templates.

    189 GitHub starsUsed in 1 repo~1.5k tokens
    Auto-check passed

Categories

Questions about Python Testing

What does Python Testing do?

Write and organize tests for scientific Python packages using pytest. Python Testing is an agent skill from Yikai-Liao/symusic. Write and organize tests for scientific Python packages using pytest.

When should I use Python Testing?

Python Testing fits situations like: tasks that involve Unit testing.

How do I install Python Testing in Claude Code?

Run `npx skills add Yikai-Liao/symusic --skill python-testing -a claude-code`. Or copy the skill folder (.agents/skills/python-testing in Yikai-Liao/symusic) into .claude/skills/python-testing in your project. Claude Code loads it when a task matches its description.

How do I install Python Testing in Codex?

Run `npx skills add Yikai-Liao/symusic --skill python-testing -a codex`. Or copy the skill folder (.agents/skills/python-testing in Yikai-Liao/symusic) into .agents/skills/python-testing in your project. Codex loads it when a task matches its description.

Can I use Python Testing in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add Yikai-Liao/symusic --skill python-testing -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/python-testing, .gemini/skills/python-testing, .github/skills/python-testing and .opencode/skills/python-testing in your project.

What does Python Testing need to run?

Going by SKILL.md and its folder, Python Testing needs Python for the scripts in its folder and the command-line tools its instructions call (pytest and pip). Our summary lists: Python 3.

Does Python Testing access the network?

SKILL.md names 7 domains. As links in the text: learn.scientific-python.org, docs.pytest.org, pytest-cov.readthedocs.io, pytest-mock.readthedocs.io, hypothesis.readthedocs.io, numpy.org and docs.python-guide.org. This is read from the text; nothing was executed.

Is Python Testing safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Python Testing use?

Python Testing is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Python Testing use?

About 3.3k tokens (SKILL.md is roughly 13k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 6.3k tokens, read only when the agent opens those files.

What are the alternatives to Python Testing?

Skills that share tags, products or a category with Python Testing: Adk Verify Snippets (google/adk-python, 22k stars), Hermetic Python Unit Tests (dimensionalOS/dimos, 4.6k stars), ONNX Runtime Test Runner (microsoft/onnxruntime, 22k stars) and Simple Modern Uv (jlevy/simple-modern-uv, 301 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Python Testing?

Yikai-Liao (a GitHub user) maintains it in Yikai-Liao/symusic, which has 189 GitHub stars. The repository holds 11 skills in this directory. The repository was last updated on August 11, 2026.

Source: Yikai-Liao/symusic on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.