En kodare

Anders Hovmöller
GitHub
twitter
email
About Blog Apps

Documentation that is never wrong

2025-08-08

The iommi docs are more correct than most projects because we take a different approach to documentation: part of the test suite is the documentation. Let’s look at an example:

def test_grouped_fields():
    # language=rst
    """
    .. _group-fields:

    How do I group fields?
    ~~~~~~~~~~~~~~~~~~~~~~

    .. uses Field.group

    Use the `group` field:
    """

    form = Form(
        auto__model=Album,
        fields__year__group='metadata',
        fields__artist__group='metadata',
    )

    # @test
    show_output(form)
    # @end

This ends up as this documentation:

2025-08-05-documentation-that-is-never-wrong.png

This is a normal test that runs with the normal test suite, with some additional markup:

With this infrastructure in place, some fixes or features can be implemented with all the required tests written as the documentation with no additional tests. This radically incentivises writing docs compared to duplicating work across tests and docs.

« BoundField vs iommi