Skip to main content

test2doc

Generate documentation from tests.

To install: pip install test2doc

Motivation

If you're like me, you think that having tests and documentation is good, but writing them is soul-killing. It's repetitive and so easy to deviate from a consistent look, make mistakes, and all that jazz.

Fortunately, there are tools out there to help out. Tools that will transform your docs into tests, so you not only can make sure that the examples in your docs actually work, but also get some test coverage from your docs.

That's doc2test stuff, and it's nice.

But what about test2doc?

What if you have a nicely commented test function like the following one in your tests/ folder:

def test_func(func, wrap):
    from inspect import signature

    # Just wrapping the func gives you a sort of copy of the func.
    wrapped_func = wrap(func)  # no transformations
    # The behavior remains the same:
    assert wrapped_func(2, "co") == "coco" == func(2, "co")
    # ... and the signature as well:
    assert str(signature(wrapped_func)) == "(a, b: str, c='hi')"

Who's going to read that?

The nerds, okay, but not the normal people, the many users you'd have if you had this as a nicely formatted documentation.

Something that would look like

About test_func(func, wrap)

from inspect import signature

Just wrapping the func gives you a sort of copy of the func.

wrapped_func = wrap(func)  # no transformations

The behavior remains the same:

assert wrapped_func(2, "co") == "coco" == func(2, "co")

... and the signature as well:

assert str(signature(wrapped_func)) == "(a, b: str, c='hi')"

You know what I'm getting at...

Do it like this:

from test2doc import code_to_docs

docs = code_to_docs(test_func)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

test2doc-0.0.3.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

test2doc-0.0.3-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file test2doc-0.0.3.tar.gz.

File metadata

  • Download URL: test2doc-0.0.3.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for test2doc-0.0.3.tar.gz
Algorithm Hash digest
SHA256 2bf2ba91df3ae9784ba011dbeba87c6aaf3030b1e538d11f115e4ea7fc0cbb93
MD5 4e23cc5c4623a3a2123dc56fab43eb37
BLAKE2b-256 ac0b6a9fce008337358826b25cb376d908b64daf1c52557dfb1a6480bbc655d3

See more details on using hashes here.

File details

Details for the file test2doc-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: test2doc-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for test2doc-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b15076e4d7c0446f998be9ba3a51afa92a97469210d985758c321713385ac304
MD5 3d976ce46a22d8918fa3e193aa2d6edf
BLAKE2b-256 da8a53a23a31d8008e13a698e45eb69d5137a419f98edd92b011a4051d93b5b5

See more details on using hashes here.

Release history Release notifications | RSS feed

0.0.4

2 files

This release

0.0.3 This release

2 files

0.0.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page