
Pytest Config
- 93 installs
- 325 repo stars
- Updated August 2, 2026
- athola/claude-night-market
Wire pytest into GitHub Actions with coverage, markers, and multi-version Python matrices for a developer’s repo.
About
This skill packages CI/CD integration patterns for pytest, centered on GitHub Actions and everyday test commands a solo or indie developer runs locally and in the cloud. It documents how to install dev extras, run full suites with HTML or XML coverage, filter by markers such as unit versus slow, rerun failures first, scale with pytest-xdist, and stop early on regressions. The workflow templates cover checkout, setup-python, editable installs, and optional codecov publishing, plus a matrix job pattern for testing across three Python versions. It is aimed at builders shipping Python libraries or services who want repeatable gates without hiring a platform team. Use it when standing up or tightening automated testing on every push rather than relying on manual pytest runs alone.
- Copy-paste GitHub Actions test.yml for push and pull_request triggers
- pytest CLI recipes: coverage, markers, failed-first, parallel (-n auto), -x, -l
- Matrix strategy example for Python 3.10, 3.11, and 3.12
- Codecov upload step paired with --cov-report=xml
- Parent skill leyline:pytest-config; reusable for .github/workflows/test.yml
Pytest Config by the numbers
- 93 all-time installs (skills.sh)
- Ranked #561 of 1,435 DevOps & CI/CD skills by installs in the Skillselion catalog
- Security screen: LOW risk (skills.sh audit)
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/athola/claude-night-market --skill pytest-configAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 93 |
|---|---|
| repo stars | ★ 325 |
| Security audit | 3 / 3 scanners passed |
| Last updated | August 2, 2026 |
| Repository | athola/claude-night-market ↗ |
What it does
Wire pytest into GitHub Actions with coverage, markers, and multi-version Python matrices for a developer’s repo.
Files
Table of Contents
Pytest Configuration Patterns
Standardized pytest configuration and patterns for consistent testing infrastructure across Claude Night Market plugins.
When To Use
- Setting up pytest configuration and fixtures
- Configuring conftest.py patterns for test infrastructure
When NOT To Use
- Non-Python projects or projects using other test frameworks
- Simple scripts that do not need test infrastructure
Quick Start
Basic pyproject.toml Configuration
[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = [
"-v",
"--cov=src",
"--cov-report=term-missing",
"--cov-fail-under=80",
"--strict-markers",
]
markers = [
"unit: marks tests as unit tests",
"integration: marks tests as integration tests",
"slow: marks tests as slow running",
]
[tool.coverage.run]
source = ["src"]
omit = ["*/tests/*", "*/migrations/*", "*/__pycache__/*"]
branch = true
[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"def __str__",
"raise NotImplementedError",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
"class .*\\bProtocol\\):",
"@(abc\\.)?abstractmethod",
]
precision = 2
show_missing = trueVerification: Run pytest --collect-only to verify discovery, pytest -v --co -q for markers, and pytest --cov for coverage thresholds.
Detailed Patterns
For detailed implementation patterns, see:
- [Conftest Patterns](modules/conftest-patterns.md) - Conftest.py templates, fixtures, test markers, and directory structure
- [Git Testing Fixtures](modules/git-testing-fixtures.md) - GitRepository helper class for testing git workflows
- [Mock Fixtures](modules/mock-fixtures.md) - Mock tool fixtures for Bash, TodoWrite, and other Claude Code tools
- [CI Integration](modules/ci-integration.md) - GitHub Actions workflows and test commands for automated testing
- Module Index: See
modules/README.mdfor module organization overview
Integration with Other Skills
This skill provides foundational patterns referenced by:
parseltongue:python-testing- Uses pytest configuration and fixturespensive:test-review- Uses test quality standardssanctum:test-*- Uses conftest patterns and Git fixtures
Reference in your skill's frontmatter:
dependencies: [leyline:pytest-config, leyline:testing-quality-standards]Exit Criteria
- pytest configuration standardized across plugins
- conftest.py provides reusable fixtures
- test markers defined and documented
- coverage configuration enforces quality thresholds
- CI/CD integration configured for automated testing
Troubleshooting
Common Issues
Tests not discovered Ensure test files match pattern test_*.py or *_test.py. Run pytest --collect-only to verify.
Import errors Check that the module being tested is in PYTHONPATH or install with pip install -e .
Async tests failing Install pytest-asyncio and decorate test functions with @pytest.mark.asyncio
CI/CD Integration
GitHub Actions workflows and test commands for automated testing.
Common Test Commands
# Run all tests
pytest
# Run with coverage
pytest --cov=src --cov-report=html
# Run specific markers
pytest -m unit
pytest -m "not slow"
# Run failed tests first
pytest --failed-first
# Parallel execution
pytest -n auto
# Verbose output with print statements
pytest -v -s
# Stop on first failure
pytest -x
# Show local variables in tracebacks
pytest -lGitHub Actions Workflow
# .github/workflows/test.yml
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install -e ".[dev]"
- run: pytest --cov --cov-report=xml
- uses: codecov/codecov-action@v4Multi-Python Version Testing
# .github/workflows/test.yml
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- run: pip install -e ".[dev]"
- run: pytest --cov --cov-report=xml
- uses: codecov/codecov-action@v4
if: matrix.python-version == '3.12'Makefile Integration
.PHONY: test
test:
pytest
.PHONY: test-cov
test-cov:
pytest --cov=src --cov-report=html --cov-report=term
.PHONY: test-fast
test-fast:
pytest -m "not slow" -x
.PHONY: test-verbose
test-verbose:
pytest -v -sConftest.py Patterns
Reusable conftest.py templates and fixture patterns for Claude Night Market plugin testing.
Project-Specific conftest.py Template
"""
Test configuration and shared fixtures for {plugin_name} plugin test suite.
This module provides common fixtures, test data, and utilities
for testing {plugin_name} skills, agents, and workflows.
"""
from __future__ import annotations
import json
import tempfile
from pathlib import Path
from typing import Any, Dict, List
from unittest.mock import Mock
import pytest
# Plugin root for test data
PLUGIN_ROOT = Path(__file__).parent.parent
@pytest.fixture
def plugin_root() -> Path:
"""Return the path to the plugin root directory."""
return PLUGIN_ROOT
@pytest.fixture
def temp_dir(tmp_path: Path) -> Path:
"""Provide a temporary directory for test isolation."""
return tmp_path
@pytest.fixture(autouse=True)
def isolate_tests(tmp_path: Path, monkeypatch):
"""Isolate tests by changing to temporary directory."""
monkeypatch.chdir(tmp_path)
yield
def pytest_configure(config):
"""Configure custom pytest markers."""
config.addinivalue_line(
"markers", "unit: Mark test as unit test"
)
config.addinivalue_line(
"markers", "integration: Mark test as integration test"
)
config.addinivalue_line(
"markers", "slow: Mark test as slow running"
)Sample Data Fixtures
@pytest.fixture
def sample_skill_frontmatter() -> str:
"""Sample valid skill frontmatter content."""
return """---
name: example-skill
description: Example skill for testing
category: testing
tags: [test, example]
tools: [Bash, TodoWrite]
complexity: low
estimated_tokens: 300
---
# Example Skill
## When to Use
Use this skill for testing purposes.
"""
@pytest.fixture
def sample_plugin_json() -> dict:
"""Sample valid plugin.json structure."""
return {
"name": "test-plugin",
"version": "1.0.0",
"description": "Test plugin for testing",
"skills": ["./skills/example-skill"],
"keywords": ["test"],
"license": "MIT",
}Standard Test Markers
Core Markers
# pytest.ini or pyproject.toml
markers = [
"unit: marks tests as unit tests (deselect with '-m \"not unit\"')",
"integration: marks tests as integration tests (deselect with '-m \"not integration\"')",
"slow: marks tests as slow running (deselect with '-m \"not slow\"')",
"e2e: marks tests as end-to-end tests",
"smoke: marks tests as smoke tests for quick validation",
]Domain-Specific Markers
# For testing-focused plugins
markers = [
"performance: marks tests as performance-focused",
"asyncio: marks tests as async-focused",
"language_detection: marks tests as language detection tests",
]
# For git-focused plugins
markers = [
"git: marks tests that require git operations",
"commit: marks tests related to commit workflows",
"pr: marks tests related to pull request workflows",
]Test Directory Structure
tests/
├── conftest.py # Shared fixtures
├── __init__.py # Make tests a package
├── unit/ # Unit tests
│ ├── test_models.py
│ └── test_utils.py
├── integration/ # Integration tests
│ ├── test_api.py
│ └── test_database.py
├── fixtures/ # Test data
│ └── sample_data.json
├── scripts/ # Script tests
│ └── test_cli.py
└── README.md # Test documentationGit Repository Testing Fixtures
Reusable fixtures for testing git-based workflows and operations.
GitRepository Helper Class
import subprocess
from pathlib import Path
class GitRepository:
"""Helper class to create and manage test Git repositories."""
def __init__(self, path: Path):
self.path = path
self.git_cmd = ["git", "-C", str(path)]
def init(self, bare: bool = False) -> None:
"""Initialize a Git repository."""
cmd = self.git_cmd + ["init", "--bare"] if bare else self.git_cmd + ["init"]
subprocess.run(cmd, check=True, capture_output=True)
def config(self, key: str, value: str) -> None:
"""Set Git configuration."""
subprocess.run(self.git_cmd + ["config", key, value], check=True, capture_output=True)
def add_file(self, file_path: str, content: str = "") -> Path:
"""Add a file to the repository."""
full_path = self.path / file_path
full_path.parent.mkdir(parents=True, exist_ok=True)
full_path.write_text(content)
return full_path
def commit(self, message: str = "Test commit") -> str:
"""Create a commit."""
subprocess.run(self.git_cmd + ["commit", "-m", message], check=True, capture_output=True)
result = subprocess.run(self.git_cmd + ["rev-parse", "HEAD"],
check=True, capture_output=True, text=True)
return result.stdout.strip()Git Repository Fixture
import pytest
@pytest.fixture
def temp_git_repo(tmp_path: Path) -> GitRepository:
"""Create a temporary Git repository for testing."""
repo = GitRepository(tmp_path)
repo.init()
repo.config("user.name", "Test User")
repo.config("user.email", "test@example.com")
repo.config("init.defaultBranch", "main")
return repoUsage Example
def test_git_workflow(temp_git_repo):
"""Test git workflow with temporary repository."""
# Add a file
temp_git_repo.add_file("README.md", "# Test Project")
# Stage and commit
subprocess.run(["git", "-C", str(temp_git_repo.path), "add", "."], check=True)
commit_hash = temp_git_repo.commit("Initial commit")
# Verify commit
assert len(commit_hash) == 40 # SHA-1 hashMock Tool Fixtures
Fixtures for mocking Claude Code tool interactions in tests.
Mock Bash Tool
from typing import Any, Dict, List
from unittest.mock import Mock
import pytest
@pytest.fixture
def mock_bash_tool():
"""Mock Bash tool for testing command execution."""
mock = Mock()
def mock_execute(command: str, **kwargs):
"""Mock bash execution with common commands."""
if "git status" in command:
return "## main...origin/main\nM file1.txt\nA file2.txt\n"
elif "git diff" in command:
return "diff --git a/file1.txt b/file1.txt\nindex 123..456 789\n"
else:
return ""
mock.side_effect = mock_execute
return mockMock TodoWrite Tool
@pytest.fixture
def mock_todo_tool():
"""Mock TodoWrite tool for testing task management."""
mock = Mock()
def mock_create(todos: List[Dict[str, Any]]):
"""Mock todo creation."""
return {"status": "success", "todos": todos}
mock.side_effect = mock_create
return mockUsage Example
def test_command_execution(mock_bash_tool):
"""Test command execution with mocked Bash tool."""
result = mock_bash_tool("git status")
assert "file1.txt" in result
assert "file2.txt" in result
def test_todo_creation(mock_todo_tool):
"""Test todo creation with mocked TodoWrite tool."""
todos = [
{"content": "Task 1", "status": "pending", "activeForm": "Doing task 1"},
{"content": "Task 2", "status": "pending", "activeForm": "Doing task 2"},
]
result = mock_todo_tool(todos)
assert result["status"] == "success"
assert len(result["todos"]) == 2Pytest Configuration Modules
This directory contains modular components of the leyline:pytest-config skill, organized following the hub-and-spoke pattern.
Module Organization
conftest-patterns.md (159 lines, ~220 tokens)
Conftest.py templates and fixture patterns:
- Project-specific conftest.py template
- Sample data fixtures (skill frontmatter, plugin.json)
- Standard test markers (unit, integration, slow, e2e)
- Domain-specific markers (git, performance, asyncio)
- Test directory structure
Reusable by: Any plugin's tests/conftest.py setup
git-testing-fixtures.md (87 lines, ~140 tokens)
GitRepository helper class for testing git workflows:
- GitRepository class implementation
- Methods: init, config, add_file, commit
- temp_git_repo fixture
- Usage examples
Reusable by: sanctum plugin, git workflow testing, commit/PR testing
mock-fixtures.md (79 lines, ~95 tokens)
Mock tool fixtures for Claude Code tools:
- mock_bash_tool fixture
- mock_todo_tool fixture
- Usage examples for testing tool interactions
Reusable by: Skills testing tool interactions, agent behavior testing
ci-integration.md (109 lines, ~120 tokens)
CI/CD integration patterns:
- Common pytest command patterns
- GitHub Actions workflow templates
- Multi-Python version testing
- Makefile integration
Reusable by: .github/workflows/test.yml, CI/CD pipeline setup
Usage Pattern
The main SKILL.md (91 lines, ~200 tokens) serves as a hub that: 1. Provides the most frequently reused pyproject.toml configuration 2. Keeps the Quick Start section for immediate use 3. Links to detailed modules for specific patterns 4. Documents integration with other skills
Total reduction: From 356 lines (750 tokens) to 91 lines (200 tokens) in main hub - 74% reduction in hub size while preserving all content.
When to Load Modules
- conftest-patterns.md - When setting up test infrastructure or configuring fixtures
- git-testing-fixtures.md - When testing git-based workflows (commits, PRs, branches)
- mock-fixtures.md - When testing skills that use Claude Code tools
- ci-integration.md - When setting up GitHub Actions or CI/CD pipelines
Related skills
FAQ
Is Pytest Config safe to install?
skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.