test-file-compaction

Refactor pytest test files by extracting fixtures and parametrizing duplicate tests.

Updated Mar 24, 2026
One-click install
npx skills add https://github.com/stevenengland/sten-agent-skills --skill test-file-compaction
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: test-file-compaction
Source: https://github.com/stevenengland/sten-agent-skills/tree/main/skills/test-file-compaction
Command: npx skills add https://github.com/stevenengland/sten-agent-skills --skill test-file-compaction

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Refactors existing test files to reduce line count and eliminate repetition without dropping any test case, assertion, or edge-case coverage. Extracts fixtures, parametrizes duplicate test bodies, introduces shared assertion helpers, and hoists repeated constants — preserving full test semantics throughout.

Core Features & Use Cases

  • Parametrize identical test bodies to collapse multiple tests into one data-driven test.
  • Extract repeated setup into fixtures to avoid duplication across tests.
  • Introduce shared assertion helpers to simplify multi-assert checks.
  • Hoist constants and literals to module scope to reduce inline repetition.
  • Flatten single-test classes to improve readability without changing behavior.
  • Preserve test IDs, order, and markers to maintain debuggability and coverage.

Quick Start

Refactor a given test file to parametrize identical tests and extract shared fixtures while preserving semantics.

Frequently Asked Questions about test-file-compaction

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

FAQPage Schema
How do I reduce pytest test duplication without losing coverage?

To reduce pytest test duplication, you can refactor test files by parametrizing identical test bodies, extracting shared setup into fixtures, and introducing shared assertion helpers. This consolidates repeated code while preserving every test case, assertion, and edge-case coverage.

How does parametrizing pytest tests consolidate duplicate test bodies?

Parametrizing pytest tests consolidates duplicate test bodies by collapsing multiple tests with identical logic into a single data-driven test. This refactoring extracts varying inputs into parameters, reducing line count while maintaining the exact same test semantics and execution coverage.

Can I refactor test suites to extract fixtures and hoist constants without changing test order?

Yes, you can refactor test suites to extract fixtures and hoist constants without changing test order. The refactoring process explicitly preserves test IDs, execution order, and markers, ensuring debuggability and behavior remain identical while producing a runnable, refactored module.

What is the best way to eliminate code smells caused by repeated assertions in pytest?

The best way to eliminate code smells from repeated assertions in pytest is to introduce shared assertion helpers. By consolidating multi-assert checks into reusable functions, you flatten single-test classes and reduce inline repetition without dropping any validation logic.

Does test file compaction work with existing pytest markers and test IDs?

Yes, test file compaction works with existing pytest markers and test IDs. The refactoring conforms to strict transformation rules that preserve all markers, test IDs, and execution order, ensuring the refactored module remains fully runnable and debuggable without semantic loss.