# pytest-patterns

Python testing guide for pytest. Helps coding assistants generate clean fixtures, manage test lifecycles, and handle test parametrization.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 854 installs · ★ 62
- Author: manutej
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/manutej/luxor-claude-marketplace/tree/HEAD/plugins/luxor-testing-essentials/skills/pytest-patterns/SKILL.md
- Updated: 2026-06-13
- HTML: https://affpapa.org/en/nevibecode/skills/pytest-patterns

## What it does

This skill guides AI assistants on structuring Python test suites with `pytest`. It establishes discovery rules across `test_*.py` files and plain functions, replacing boilerplate `unittest.TestCase` classes with clear `assert` expressions.

It details fixture design patterns across all lifecycle scopes, from isolated test functions to session-level database setups. The guidance covers teardown steps via `yield` and factory functions that yield mock models. It also introduces parametrization techniques using marks and labeled inputs for edge case coverage.

A test class defining `__init__` breaks default pytest discovery. The skill ensures the assistant avoids such mistakes when scaffolding test files.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add manutej/luxor-claude-marketplace --skill pytest-patterns -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/pytest-patterns/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/pytest-patterns/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add manutej/luxor-claude-marketplace --skill pytest-patterns -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/pytest-patterns/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add manutej/luxor-claude-marketplace --skill pytest-patterns -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/pytest-patterns/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install manutej/luxor-claude-marketplace pytest-patterns
```

2. **Manually: put the files in place**
- File: `.github/skills/pytest-patterns/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add manutej/luxor-claude-marketplace --skill pytest-patterns -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/manutej/luxor-claude-marketplace --path plugins/luxor-testing-essentials/skills/pytest-patterns
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/pytest-patterns/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add manutej/luxor-claude-marketplace --skill pytest-patterns -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/manutej/luxor-claude-marketplace/tree/HEAD/plugins/luxor-testing-essentials/skills/pytest-patterns/SKILL.md

## When to use it
- Configure hierarchical fixtures with teardown via `yield`
- Parametrize test functions across multiple input combinations
- Migrate legacy `unittest` suites to idiomatic `pytest` assertions
- Implement factory fixtures to generate mock domain entities

## Example prompts
- Create a session-scoped database fixture with automatic cleanup
- Parametrize this test function to cover edge cases and invalid inputs
- Refactor this `unittest` test suite into clean `pytest` conventions

## Similar
- [pytest-advanced](https://affpapa.org/en/nevibecode/skills/pytest-advanced.md) — skill · 351 installs
- [pytest](https://affpapa.org/en/nevibecode/rules/pytest.md) — rule · ★ 3579
- [Pytest Testing](https://affpapa.org/en/nevibecode/skills/pytest-testing.md) — skill · 521 installs
- [python-testing-patterns](https://affpapa.org/en/nevibecode/skills/python-testing-patterns.md) — skill · 36943 installs
- [pytest-skill](https://affpapa.org/en/nevibecode/skills/pytest-skill.md) — skill · 412 installs
- [python-testing](https://affpapa.org/en/nevibecode/skills/laurigates-python-testing.md) — skill · 427 installs

From the same set: [manutej/luxor-claude-marketplace](https://affpapa.org/en/nevibecode/by/manutej/luxor-claude-marketplace.md) — 59 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
