Skip to content

API Reference

inline_tests

Inline tests for Python — colocate tests with implementation, Rust-style.

MARKER = '__inline_test__' module-attribute

Attribute name set on decorated test functions/classes.

test(obj=None, *, reason=None)

test(obj: T) -> T
test(*, reason: str | None = ...) -> Callable[[T], T]

Mark a function or class as an inline test.

Source code in src/inline_tests/__init__.py
def test(obj: T | None = None, *, reason: str | None = None) -> T | Callable[[T], T]:
    """Mark a function or class as an inline test."""

    def mark(target: T) -> T:
        setattr(target, MARKER, reason or True)
        return target

    return mark(obj) if obj is not None else mark

Decorator

test

@test
def my_test():
    ...

@test(reason="why this test exists")
def my_test():
    ...

Marks a function or class as an inline test.

Parameters:

Name Type Required Description
reason str No Documentation for why the test exists

Returns: The original function, unchanged except for a marker attribute.

it

Alias for test. Use for BDD-style test names:

@it
def should_handle_empty_input():
    ...

Constants

MARKER

MARKER: Final[str] = "__inline_test__"

The attribute name set on decorated functions. Used internally by the plugin for collection.

version

__version__: str

Package version string, read from package metadata.

Plugin hooks

The plugin registers these pytest hooks:

  • pytest_addoption - Adds --inline-tests flag
  • pytest_collect_file - Collects @test-decorated items from non-test files
  • pytest_collection_modifyitems - Deduplicates items between collectors