Agent skill

Polylith Migrate Refactor Tests

by DavidVujic in DavidVujic/python-polylith

[Internal sub-skill of polylith-migrate-orchestrator. An agent skill from DavidVujic/python-polylith.

MITAuto-check passedTesting & QA

Install Polylith Migrate Refactor Tests

skills CLI
$ npx skills add DavidVujic/python-polylith --skill polylith-migrate-refactor-tests -a claude-code

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

GitHub CLI
$ gh skill install DavidVujic/python-polylith polylith-migrate-refactor-tests --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/DavidVujic/python-polylith.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/polylith/migrate-project/polylith-migrate-refactor-tests .claude/skills/polylith-migrate-refactor-tests && 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
polylith-migrate-refactor-tests
GitHub stars
553
Token cost
~2.1k tokens
SKILL.md length
988 words
Files
1
Skills in repo
37
Repo updated
First seen
Licence
MIT

At a glance

[Internal sub-skill of polylith-migrate-orchestrator. An agent skill from DavidVujic/python-polylith.

  • Works in 4 steps: Classify each unit test file → Move test files → Update imports and mock patch strings → …
  • Tasks that involve Unit testing
  • SKILL.md covers Goal, Scope, Shared test helpers & the… and Inputs, plus 5 more sections
  • Calls git and pytest

What it does

Polylith Migrate Refactor Tests is an agent skill from DavidVujic/python-polylith. [Internal sub-skill of polylith-migrate-orchestrator. Do not load directly — load polylith-migrate-orchestrator first, which drives all phases.] Restructure unit tests to align with the workspace's Polylith theme.

Its SKILL.md is about 2.1k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Testing & QA, covering Unit testing and Refactoring. It works with pytest. The repository describes itself as: Tooling support for the Polylith Architecture in Python. The licence is MIT.

When your agent uses it

  • Tasks that involve Unit testing
  • Tasks that involve Refactoring

Example prompts

  • “/polylith-migrate-refactor-tests”

Workflow steps

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

  1. Classify each unit test file
  2. Move test files
  3. Update imports and mock patch strings
  4. Update RUN_TEST_CMD

What it can do on your machine

Read from SKILL.md and the folder at commit a7a80f2. 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

    Shell commands in SKILL.md call:

    • git
    • pytest

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

  • Network

    No URLs in SKILL.md. Its commands use git, which can reach the network depending on how they are called.

    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

Polylith Migrate Refactor Tests loads about 2.1k tokens when it runs. Until then it costs about 62 tokens; SKILL.md has 988 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~62
When it runs · the whole SKILL.md, loaded when a task matches
~2.1k

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 DavidVujic/python-polylith at commit a7a80f2, republished under its MIT licence (© DavidVujic). 988 words, ~2,070 tokens.

Download SKILL.mdSave it as .claude/skills/polylith-migrate-refactor-tests/SKILL.md (or your agent's skills folder).
name
polylith-migrate-refactor-tests
description
[Internal sub-skill of `polylith-migrate-orchestrator`. Do not load directly — load `polylith-migrate-orchestrator` first, which drives all phases.] Restructure unit tests to align with the workspace's Polylith theme.

Skill: polylith-migrate-refactor-tests

Goal

Restructure unit tests so they live next to the brick they test, following the workspace's Polylith theme (loose or tdd).

Scope

  • Unit tests only. Integration tests typically stay in a shared location (e.g., test/integration/ or test/<project>/integration/). Do not redistribute them across bricks.
  • Structure only. Reorganize test files and update imports/mock patch strings. Do not rewrite test logic or fixtures unless an import/path change makes it strictly necessary.

Shared test helpers & the namespace-merge hazard (read before moving)

Two real traps when moving unit tests next to their bricks:

  1. Shared test-support packages stop resolving. If tests import shared helpers/fixtures by package (e.g. from <svc>_service.helpers import …, from <svc>_service.fixtures import …), those resolve today only because the service test dir sits on sys.path (pytest inserts the topmost non-package dir). Once a test moves to test/components/<TARGET_TOP_NS>/<comp>/ (no __init__.py), pytest inserts the leaf test dir instead, and the shared import breaks.
  2. Do NOT "fix" it by adding test/ to pythonpath. That makes test/<…>/<TARGET_TOP_NS>/<brick>/ directories merge into the real <TARGET_TOP_NS> namespace and collide with components/<TARGET_TOP_NS>/<brick> / bases/<TARGET_TOP_NS>/<brick> — an ambiguous, hard-to-debug namespace package.
Two sanctioned layouts — pick one
  • Per-brick (the target table below). Use it after making shared helpers reachable without putting test/ on the path: convert them to conftest.py fixtures (pytest injects fixtures with no import), or move pure helper functions to an on-path support location. Unit tests then live under test/<theme>/<TARGET_TOP_NS>/<brick>/.
  • Workspace-level service dir. Keep the project's tests under a single test/<svc>_service/ directory (the importable, valid-package name that polylith-migrate-prepare-project created). Shared helpers stay co-located and importable. Choose this when converting helpers to fixtures isn't worth it; record the choice in state.md. This still satisfies "tests at workspace level".

If unsure, the workspace-level service dir is the lower-risk default.

Inputs

From migration/<PROJECT>/state.md:

  • TARGET_TOP_NS
  • RUN_TEST_CMD (will be updated by this skill)
  • RUN_LINT_CMD, RUN_TYPECHECK_CMD (optional)

From migration/<PROJECT>/manifest.md:

  • List of all bricks (bases and components) with their module maps.

From workspace.toml:

  • [tool.polylith.structure].theme (loose or tdd).

From test/:

  • Current test directory structure.

All inputs from state.md are assumed to satisfy the validation rules in polylith-migrate-discover (### Validation rules). Validate before proceeding.

Target layout

ThemeTest path for a baseTest path for a component
loosetest/bases/<TARGET_TOP_NS>/<base>/test_*.pytest/components/<TARGET_TOP_NS>/<component>/test_*.py
tddbases/<base>/test/<TARGET_TOP_NS>/<base>/test_*.pycomponents/<component>/test/<TARGET_TOP_NS>/<component>/test_*.py

Steps

1. Classify each unit test file

For each test_*.py under the current test root:

  1. Read its import statements and mock.patch("...") strings.
  2. Identify the primary brick under test — usually the one most imported or the one mock-patched. Tie-break by file name (test_user_handler.py → <user_handler base or component>).
  3. Record the classification in a table you keep in scratch (do not commit a separate file for this — it's transient):
Test filePrimary brickTarget path

If a test exercises 2+ bricks at integration level, classify it as integration and move it to test/integration/ instead.

2. Move test files
  • Create the target directories per the theme matrix above.
  • Move each test_*.py to its brick's test directory.
  • For each conftest.py:
    • Brick-scoped fixtures (referenced only by tests under one brick) → move to that brick's test directory.
    • Workspace-shared fixtures (cross-brick) → keep one test/<TARGET_TOP_NS>/conftest.py or test/conftest.py.
3. Update imports and mock patch strings
  • Update any from tests.<x> imports that survived to the new layout.
  • Update mock.patch("<old.path>") strings. Brick reshuffling earlier in the migration may have changed where the patched symbol now lives — use grep to locate the target symbol's new path and align the patch string. Patching a wrong path silently succeeds and the test will pass for the wrong reason — verify by intentionally breaking the target function and checking that the test fails.
Show full SKILL.md (408 more words)Show less
4. Update RUN_TEST_CMD
  • Set RUN_TEST_CMD in state.md to a command that collects from the new test root (typically <POLY_CMD_PREFIX_RUN> pytest test/ for loose, or per-brick collection for tdd).
  • Verify the test count after the move equals the baseline recorded in polylith-migrate-discover. A drop in collected tests means files were lost or pytest discovery is misconfigured.

Verify

  • RUN_TEST_CMD succeeds and collects the same number of tests as the baseline from polylith-migrate-discover.
  • If set, RUN_LINT_CMD succeeds.
  • POLY_CMD_PREFIX check is still green.

Common failure modes

SymptomLikely causeRemediation
pytest collects fewer tests than beforeThe old test root is no longer on pytest's path; or duplicate conftest.py files silently shadow each other.Update [tool.pytest.ini_options].testpaths (or pass paths explicitly in RUN_TEST_CMD). Run pytest --collect-only and diff against baseline collection.
fixture '<name>' not foundThe fixture was in a conftest.py you moved into a brick's test dir; tests in another brick can no longer see it.Either move the fixture up to a higher-scope conftest.py, or duplicate it (only if cheap). Don't import fixtures across conftest.py files.
Tests pass but assert nothing useful (mock.patch no longer hits anything)Patch string still points at the pre-migration module path.Re-derive the patch path: <TARGET_TOP_NS>.<brick_name>.<module>.<symbol>. Validate by deliberately breaking the patched function and confirming the test fails.
ImportError: cannot import name 'fixture_<x>' from conftest.pyA conftest.py imports a moved test helper module that didn't follow it.Move the helper next to the new conftest.py, or import it from its new brick path.
Tests for moved code suddenly find themselves under a brick name that doesn't match their contentMisclassification in step 1.Re-read the test's imports — the brick most imported is the one that owns the test. Move and update.
ModuleNotFoundError: No module named '<svc>_service' after moving a test to test/<theme>/<TARGET_TOP_NS>/<brick>/Shared test-support package is no longer on sys.path.Use a sanctioned layout (above): convert the helpers to conftest fixtures, or keep tests in the workspace-level <svc>_service/ dir. Do not add test/ to pythonpath (namespace merge with the real bricks).
Verification fails and you can't quickly diagnosePhase commit not yet made.git reset --hard HEAD to roll back to the previous phase's commit and consult the user.

Commit

After verification passes, commit this phase to the migration branch:

bash
git add -A && git commit -m "migrate(<PROJECT>): phase <N> — refactor-tests"

Substitute <PROJECT>, <N>, and <phase-name> from state.md and the orchestrator's phase table. Do not proceed to the next phase without a clean commit — the per-phase commit is the rollback point for the next phase's failure-mode tables.

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

Files

Just SKILL.md in .agents/skills/polylith/migrate-project/polylith-migrate-refactor-tests of DavidVujic/python-polylith.

Open the folder on GitHubat commit a7a80f2

Compare with similar skills

Polylith Migrate Refactor Tests 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.

Polylith Migrate Refactor Tests compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Polylith Migrate Refactor Tests this skillDavidVujic/python-polylith553—~2.1kAutomated safety check: PassMIT
Write Vibe Testsmistralai/mistral-vibe5.1k—~1.2kAutomated safety check: PassApache-2.0
Python Regression Test GeneratorArabelaTso/Skills-4-SE253—~4.1kAutomated safety check: PassApache-2.0
Adk Verify Snippetsgoogle/adk-python22k—~1.4kAutomated safety check: PassApache-2.0
TDD WorkflowhellangleZ/burn-in-cceverywhere-ralph11211 repos~2.4kAutomated safety check: PassNone
Hermetic Python Unit TestsdimensionalOS/dimos4.6k—~1.4kAutomated safety check: PassCustom licence

Similar skills

  • Write Vibe Tests

    mistralai/mistral-vibe

    Official

    Guides writing or refactoring tests for the Mistral Vibe CLI agent so they check behavior through stable boundaries, like tool invocation or saved session shape, instead of internal calls.

    5.1k GitHub stars~1.2k tokensUpdated yesterday
    Testing & QAAuto-check passed
  • Python Regression Test Generator

    ArabelaTso/Skills-4-SE

    Automatically generates regression tests for Python codebases by analyzing changes between old and new code versions and their existing tests.

    253 GitHub stars~4.1k tokensUpdated 1 mo ago
    Testing & QAAuto-check passed
  • 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
  • TDD Workflow

    hellangleZ/burn-in-cceverywhere-ralph

    A skill your agent uses when writing new features, fixing bugs, or refactoring code.

    112 GitHub starsUsed in 11 repos~2.4k tokens
    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
  • Test Guard

    amElnagdy/guard-skills

    Reviews newly written or edited tests against nine rules that cut test bloat, such as mock-heavy checks and near-duplicate cases, before they are committed.

    1.3k GitHub starsUsed in 2 repos~2.1k tokens
    Testing & QAAuto-check passed

More from DavidVujic/python-polylith

All 37 skills in this repo
  • Polylith Base Creation

    DavidVujic/python-polylith

    Create a Polylith base with poly create base — the entry point of a deployable application (HTTP API, CLI, message-queue consumer, AWS Lambda handler, GCP Cloud Function, scheduled job).

    553 GitHub stars~757 tokensUpdated 2 days ago
    Auto-check passed
  • Polylith Check

    DavidVujic/python-polylith

    Validate a Polylith workspace with poly check — the canonical CI gate.

    553 GitHub stars~972 tokensUpdated 2 days ago
    Auto-check passed
  • Polylith Component Creation

    DavidVujic/python-polylith

    Create a Polylith component with poly create component — a reusable, isolated brick implementing business logic, a feature, a domain module, or a capability.

    553 GitHub stars~800 tokensUpdated 2 days ago
    Auto-check passed
  • Polylith Dependency Management

    DavidVujic/python-polylith

    Add or manage third-party dependencies in a Polylith workspace.

    553 GitHub stars~643 tokensUpdated 2 days ago
    Auto-check passed
  • Polylith Dependency Visualization

    DavidVujic/python-polylith

    Visualize brick × brick dependencies with poly deps — find circular dependencies, inspect a brick's public interface, and detect interface-bypass violations.

    553 GitHub stars~906 tokensUpdated 2 days ago
    Auto-check passed
  • Polylith Diff

    DavidVujic/python-polylith

    List Polylith bricks whose implementation changed since a git tag using poly diff.

    553 GitHub stars~1.1k tokensUpdated 2 days ago
    Auto-check passed

Works with

Categories

Questions about Polylith Migrate Refactor Tests

What does Polylith Migrate Refactor Tests do?

[Internal sub-skill of polylith-migrate-orchestrator. An agent skill from DavidVujic/python-polylith. Polylith Migrate Refactor Tests is an agent skill from DavidVujic/python-polylith. [Internal sub-skill of polylith-migrate-orchestrator.

When should I use Polylith Migrate Refactor Tests?

Polylith Migrate Refactor Tests fits situations like: tasks that involve Unit testing; tasks that involve Refactoring.

How do I install Polylith Migrate Refactor Tests in Claude Code?

Run `npx skills add DavidVujic/python-polylith --skill polylith-migrate-refactor-tests -a claude-code`. Or copy the skill folder (.agents/skills/polylith/migrate-project/polylith-migrate-refactor-tests in DavidVujic/python-polylith) into .claude/skills/polylith-migrate-refactor-tests in your project. Claude Code loads it when a task matches its description.

How do I install Polylith Migrate Refactor Tests in Codex?

Run `npx skills add DavidVujic/python-polylith --skill polylith-migrate-refactor-tests -a codex`. Or copy the skill folder (.agents/skills/polylith/migrate-project/polylith-migrate-refactor-tests in DavidVujic/python-polylith) into .agents/skills/polylith-migrate-refactor-tests in your project. Codex loads it when a task matches its description.

Can I use Polylith Migrate Refactor Tests 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 DavidVujic/python-polylith --skill polylith-migrate-refactor-tests -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/polylith-migrate-refactor-tests, .gemini/skills/polylith-migrate-refactor-tests, .github/skills/polylith-migrate-refactor-tests and .opencode/skills/polylith-migrate-refactor-tests in your project.

What does Polylith Migrate Refactor Tests need to run?

Going by SKILL.md and its folder, Polylith Migrate Refactor Tests needs the command-line tools its instructions call (git and pytest).

Does Polylith Migrate Refactor Tests access the network?

SKILL.md contains no URLs. Its commands use git, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Polylith Migrate Refactor Tests 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 Polylith Migrate Refactor Tests use?

Polylith Migrate Refactor Tests 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 Polylith Migrate Refactor Tests use?

About 2.1k tokens (SKILL.md is roughly 8.3k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Polylith Migrate Refactor Tests?

Skills that share tags, products or a category with Polylith Migrate Refactor Tests: Write Vibe Tests (mistralai/mistral-vibe, 5.1k stars), Python Regression Test Generator (ArabelaTso/Skills-4-SE, 253 stars), Adk Verify Snippets (google/adk-python, 22k stars) and TDD Workflow (hellangleZ/burn-in-cceverywhere-ralph, 112 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Polylith Migrate Refactor Tests?

DavidVujic (a GitHub user) maintains it in DavidVujic/python-polylith, which has 553 GitHub stars. The repository holds 37 skills in this directory. The repository was last updated on October 4, 2026.

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