Skip to content

CLI

The itest command

itest is a thin wrapper around pytest with --inline-tests enabled:

itest

Equivalent to:

pytest --inline-tests

Passing arguments

All pytest arguments work:

# Verbose output
itest -v

# Run specific file
itest src/auth/login.py

# Run specific test
itest -k "test_name"

# Stop on first failure
itest -x

# Show print output
itest -s

Common patterns

# Run only inline tests in src/
itest src/

# Run with coverage
itest --cov=src

# Run in parallel
itest -n auto

# Run specific markers
itest -m "not slow"

Exit codes

Standard pytest exit codes:

Code Meaning
0 All tests passed
1 Some tests failed
2 Test execution interrupted
3 Internal error
4 pytest usage error
5 No tests collected

Production builds

Ship as-is. The @test decorator is a no-op at runtime. Tests never execute unless you run itest. Zero overhead.

Strip tests. Remove @test functions and imports before packaging:

itest strip src/ -o dist/

The stripper removes:

  • Functions and classes decorated with @test or @it
  • @test methods inside regular classes
  • from inline_tests import test and similar imports

Build system integration

Hatchling — Automatic stripping during hatch build or uv build:

[build-system]
requires = ["hatchling>=1.25", "inline-tests>=0.0.1"]
build-backend = "hatchling.build"

[tool.hatch.build.hooks.inline_tests]

That's it. Now uv build or hatch build strips tests automatically:

$ uv build
Stripped 42 files
Successfully built dist/mypackage-0.1.0-py3-none-any.whl

Configuration:

[tool.hatch.build.hooks.inline_tests]
sources = ["src", "lib"]  # Directories to strip (default: ["src"])

Manual stripping — For build systems without hook support:

itest strip src/ -o build/src
cd build && uv build