CLI¶
The itest command¶
itest is a thin wrapper around pytest with --inline-tests enabled:
Equivalent to:
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:
The stripper removes:
- Functions and classes decorated with
@testor@it @testmethods inside regular classesfrom inline_tests import testand 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:
Configuration:
[tool.hatch.build.hooks.inline_tests]
sources = ["src", "lib"] # Directories to strip (default: ["src"])
Manual stripping — For build systems without hook support: