On demand

Run only the tests your change can affect

Claude maps which Python files import which, then lists only the test files your change can reach. During a build, TLM Forge tells Claude to run just those while it works, and every test at the end. You can also ask for the list any time.

  • How it startsAsk for it
  • Runs onAny time you ask; also during Medium and Deep builds
An editor shows billing/invoice.py with the line "from billing.tax import tax_for" highlighted. A dotted line runs to a card from the TLM Forge terminal explaining that test_invoice.py never names tax.py but imports invoice.py, so it is in the impacted set, and to run these 3 tests while iterating.

How to use it

Ask Claude in plain English, for example:

  • which tests should I run after this diff?
  • test impact for this diff
  • skip tests that don't matter

Ask in plain English at any time. During a /tlmforge:build run on Medium or Deep work, TLM Forge also tells Claude to use it while building and while fixing review findings: only the affected tests while iterating, then the full suite once at the end of the build and again before the final review (Stage 5).

Words you will see on this page

Test suite
All the tests in your project.
Import graph
A map of which files import which other files.
Impacted tests
Test files that import your changed file, directly or through a chain of other files.
conftest.py and fixtures
Shared test setup files that many tests use, so a change there can affect every test.
Static analysis
Reading the code without running it.
Final review (Stage 5)
The review TLM Forge runs on the finished change.

Three ways to pick tests after a change

ApproachSpeedWhat it misses
Run the whole suite after every editSlowNothing, but you wait every time
Pick tests by file nameFastTests that reach your change through another file
The test impact listFastRuntime imports, relative imports and config files loaded at runtime

When you get a short list, and when to run everything

What changedWhat happens
A normal Python source fileYou get the test files that import it, directly or indirectly
conftest.py or a file in a fixtures folderNo list, just a note recommending the full suite
Security code (auth, encryption, payments)Claude is told to run the full suite anyway
A bigger change that maps to only one to three testsClaude is told to do one full run before merging
A deleted fileSkipped with a warning, so run the full suite
A third-party package upgradeNot visible to the tool, so run the full suite

What it does

Running every test after each small edit is slow. Guessing which few to run misses things. The test impact graph replaces the guess with a fact: which test files import the code you changed, either directly or through a chain of other files. It is a small Python script that Claude runs for you, with nothing extra to install.

The script reads every Python file in your source and test folders without running them. It notes each import, then works backwards from your changed files to every file that depends on them. It keeps only the test files and prints their full paths, one per line, ready to pass to pytest.

It plays safe where it cannot see. If a shared test setup file (conftest.py or a fixtures folder) changed, it gives no list and recommends the full suite, since those affect every test. Claude is also told to run the full suite for security-related changes, and to do one full run before merging when a bigger change maps to only one to three tests.

How it works, step by step

  1. Read every Python file

    The script collects all .py files in your source and test folders and reads their import lines. A file it cannot parse adds nothing.

  2. Build the map

    Each import becomes a link between two files. The map is then reversed, so it can answer "who depends on this file?"

  3. Walk out from your change

    Starting at the files you changed, it follows the links to every file that depends on them, directly or indirectly.

  4. Keep only tests

    It keeps files in the tests folder, or with test_ in the name, or ending in _test.py, and prints their paths.

  5. Run those, then everything

    During a build, TLM Forge tells Claude to run the listed tests while it works, then the full suite once at the end of the build and again before the final review.

What it looks like

Two sample runs (invented paths). First, a change to billing/tax.py lists the three test files that reach it. Second, a change to the shared test setup file gives no list and recommends the full suite.

$ python3 analyzer.py --src-root . --tests-root tests \
    --changed-files billing/tax.py
/work/shop/tests/test_checkout.py
/work/shop/tests/test_invoice.py
/work/shop/tests/test_tax.py

$ python3 analyzer.py --src-root . --tests-root tests \
    --changed-files tests/conftest.py
# conftest.py or fixtures changed, recommend running full suite

Why it is better

Facts, not guesses

Without TLM Forge, picking tests by file name misses tests that reach your change through another file. With it, the script follows real imports, so those tests are included.

Fast while working, complete at the end

Without it, you choose between waiting on every test and hoping you picked the right few. With it, Claude is told to run the affected tests while working and the full suite at the end of the build.

Safe where it cannot see

Without it, a shared setup change can slip by on a partial run. With it, a conftest or fixture change gets no shortcut list, only a recommendation to run everything.

Ready to use

Without it, you build the test list by hand. With it, the output is one path per line, ready for pytest or a pre-push script.

Good to know

  • Python only. JavaScript, end-to-end UI tests and other languages need their own approach.
  • It reads code without running it, so it cannot see imports made at runtime (such as importlib.import_module) or config, YAML or JSON files loaded at runtime. Keep an always-run list of tests for those.
  • Relative imports (from .tax import x, or from . import tax) are not followed, so tests reached only that way are missed. If your project uses relative imports, run the full suite before merging.
  • Run the full suite after a package upgrade or when a change deletes a file. The script cannot see upgrades, and it skips deleted files with a warning.
  • It lists test files, not single test functions, and it does not show the import chain behind each one.

Related features