Skip to main content

Generate documentation from tests

Project description

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)

Project details


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.2.tar.gz (4.9 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.2-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: test2doc-0.0.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for test2doc-0.0.2.tar.gz
Algorithm Hash digest
SHA256 82cf8f697fa5822e8b0544966b9a521edd614e4f44c177083d62e432338fbad0
MD5 d0fd293a8156fde68b2b7264307febc1
BLAKE2b-256 9608ca233e3a1616921265c98ca656c4f437fbb5ec9c58267c2a9179d014be41

See more details on using hashes here.

File details

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

File metadata

  • Download URL: test2doc-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for test2doc-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4fb99b56c11928a3f0f3fb8a122b258701b7ae3ebe82d66bf71dce32d07f3acd
MD5 c9e1ed3d0fc539b2bbe3ed6dae085e67
BLAKE2b-256 81b8ac60622db6fe9bdd669137c0f50d2132ace9b136c8ffb818aa1afbacc00a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page