Skip to content

inline-tests

Rust-like inline testing in Python, without the compiler.

from inline_tests import test

def authenticate(user, password):
    if not user or not password:
        return None
    return verify_credentials(user, password)

@test
def rejects_empty_credentials():
    assert authenticate("", "pass") is None
    assert authenticate("user", "") is None
$ itest
========================= test session starts =========================
collected 1 item

auth/login.py .                                                  [100%]

========================== 1 passed in 0.01s ==========================

Why?

Tests live in one place. Code lives in another. You change a function and forget to update its test. Or you write the test later. Or never.

Rust solved this years ago. Tests live next to the code they test. You see them together. You change them together. They can't drift because they're in the same file.

Python never had this. Until now.

Features

@test decorator. Mark any function as a test. The function still works normally at runtime.

Full pytest. Fixtures, parametrize, async, markers, plugins. Everything pytest offers, because this is pytest.

Zero overhead. Tests are invisible unless you run itest. No imports, no collection; nothing happens.

No ceremony. No mirroring directory structures. No tests/ folder required. Just @test where the code is.

Production-ready. itest strip removes test code from source. Ship without test overhead.

Quick Start

uv tool install inline-tests
itest

That's it.

Next Steps


For LLMs:

Viewing locally: uv sync --extra docs && uv run mkdocs serve -> localhost:8000