Skip to main content

A Python doctest runner for AsciiDoc documents and docstrings.

Project description

= asciidoctest: Python Doctest Runner for AsciiDoc
:toc: left
:idprefix:
:idseparator: -

`asciidoctest` is a modern, high-developer-experience (DX) Python doctest runner specifically designed to parse, collect, and execute tests directly from AsciiDoc (`.adoc`) files and Python docstrings.

Unlike traditional approaches relying on fragile regular expressions, `asciidoctest` integrates robust AST-based parsing using `asciidoctrine` and `asciidocstring` to provide accurate, reliable, and compliant testing of documentation.

== Features

* **AST-Based Parsing**: Robust structure parsing using `asciidoctrine` (AsciiDoc parser) and `asciidocstring` (AsciiDoc docstring parser).
* **Flexible Modes**:
- `explicit` (default): Only executes blocks with the `test` attribute/role (e.g. `[source,python,test]` or `[.test]\n[source,python]`).
- `eager`: Executes all `[source,python]` code blocks across your document.
* **Shared Sequential State**: Within a standalone AsciiDoc document, subsequent blocks share state top-to-bottom sequentially. State is completely isolated between separate files.
* **Modern Pytest Integration**: Automatic discovery of `.adoc` files and docstrings via custom pytest collectors.
* **Unittest Compatibility**: Out-of-the-box support for `DocTestSuite` and `DocFileSuite`.

== Installation

To install `asciidoctest` in your project:

[source,bash]
----
pip install asciidoctest
----

== Pytest Integration

`asciidoctest` registers a `pytest` plugin automatically. Simply run `pytest` in your project directory:

[source,bash]
----
pytest
----

=== Configuration

You can configure target matching behavior in your `pyproject.toml` or `pytest.ini`:

[source,ini]
----
[pytest]
asciidoctest_mode = eager
----

Alternatively, you can supply the `--asciidoctest-mode` argument via command line:

[source,bash]
----
pytest --asciidoctest-mode=eager
----

== Unittest Integration

If you use the standard library `unittest` package, you can easily load and run tests using `DocFileSuite` or `DocTestSuite`:

[source,python]
----
import unittest
from asciidoctest import DocFileSuite

def suite():
return DocFileSuite("README.adoc")

if __name__ == "__main__":
unittest.main(defaultTest="suite")
----

== Examples (Interactive & Non-Interactive)

Below are simple testable blocks that demonstrate sequential state-sharing and execution.

We can run interactive python sessions with expected outputs:

[source,python,test]
----
>>> x = "asciidoctest"
>>> x.upper()
'ASCIIDOCTEST'
----

We can also run non-interactive scripts with standard Python assertions. Note that because they run in the same document, the variable `x` defined above is shared sequentially:

[source,python,test]
----
assert x == "asciidoctest"
y = len(x)
assert y == 12
----

Standard `doctest` features like ellipsis work perfectly:

[source,python,test]
----
>>> print("Hello ... World")
Hello ... World
----

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

asciidoctest-0.1.0a1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

asciidoctest-0.1.0a1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file asciidoctest-0.1.0a1.tar.gz.

File metadata

  • Download URL: asciidoctest-0.1.0a1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for asciidoctest-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 e15c881bdf499aa333aab2cbeeda7911bc789359d901941bcb0c1749bd007b0e
MD5 637b25d6ae1bfdf17d748e88e0a418f6
BLAKE2b-256 00fd4edf1007b8132948a869fe1047a5655e7a29772d5da8355dc7826f65ed76

See more details on using hashes here.

File details

Details for the file asciidoctest-0.1.0a1-py3-none-any.whl.

File metadata

  • Download URL: asciidoctest-0.1.0a1-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for asciidoctest-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 ded06698a1bd71d14d6a001dd3131935afe7e54d9069c9915acb88cfcf17c22b
MD5 fb665ec5940ea1f1cadb28b6aca0a271
BLAKE2b-256 9b596b15a540208ff92ffa772dbcddc1111a827f7ece8b00efcd02499c8ad3e9

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