Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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

`asciidoctest` is a Python doctest runner designed to parse, collect, and execute tests from AsciiDoc (`.adoc`) files and Python docstrings.

It integrates AST-based parsing using `asciidoctrine` and `asciidocstring` to provide accurate and standard-compliant testing of documentation.

== Features

* **AST-Based Parsing**: Structural parsing using `asciidoctrine` (AsciiDoc parser) and `asciidocstring` (AsciiDoc docstring parser).
* **Execution Modes**:
- `explicit` (default): Only executes blocks with the `test` attribute or role (e.g., `[source,python,test]` or `[.test]\n[source,python]`).
- `eager`: Executes all `[source,python]` code blocks across the document.
* **Shared State**: Within a single AsciiDoc document, subsequent blocks share execution state sequentially top-to-bottom. Execution state is completely isolated between separate files.
* **Pytest Integration**: Automatic discovery and execution of `.adoc` files and Python docstrings via registered pytest collectors.
* **Unittest Compatibility**: Suite wrappers (`DocTestSuite` and `DocFileSuite`) designed to integrate with the standard library `unittest` runner.

== Installation

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

== Pytest Integration

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

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

=== Configuration

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

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

Alternatively, you can supply the `--asciidoctest-mode` flag:

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

== Unittest Integration

To use the standard library `unittest` package, load 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

Below are standard test blocks demonstrating interactive and script-based execution.

=== Interactive Session

We can run interactive Python sessions with expected outputs:

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

=== Sequential Script Block

We can run script-based test blocks with standard Python assertions. Because they share execution state sequentially, variables defined in previous blocks are accessible:

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

=== Directives Support

Standard `doctest` directives such as `ELLIPSIS` are supported:

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

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.0a2.tar.gz (16.6 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.0a2-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: asciidoctest-0.1.0a2.tar.gz
  • Upload date:
  • Size: 16.6 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.0a2.tar.gz
Algorithm Hash digest
SHA256 5014ddad66f625b3d2335969a18b2b9af96cb6cecab4a1dbd898c7117d64b371
MD5 90183c6598125e5bd6ca2e40d66c7f7b
BLAKE2b-256 86d5bae3896ffd200c64401c324e747b8d4525695dccff788a93e449522a170f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asciidoctest-0.1.0a2-py3-none-any.whl
  • Upload date:
  • Size: 12.5 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.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 1a4acbcb288ba9f432e6ae7a9923c3b1a9262fac9bad243c79472abdfcdac55e
MD5 2dd10a1893cae1ef3e60f05a58653f0e
BLAKE2b-256 e47a8bad766bf1e4004f4ad2059b207e73e79c9499eb958c8796191b5c9ab25a

See more details on using hashes here.

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