Developer Handbook
This document describes the codebase architecture, testing conventions, and development workflows for asciidoctest.
Please review the Security Policy before running untrusted code blocks during local development.
Codebase Architecture
asciidoctest extracts and verifies code blocks from AsciiDoc (.adoc) files and Python docstrings.
Component Overview
graph TD
A[Source Files: .adoc, .py, Modules] --> B[pytest_plugin / unittest_integration / docstring_extractor]
B --> C[parser.py]
C --> D[asciidoctrine / asciidocstring]
D --> E[TestBlock List + Section IDs]
E --> F[runner.py]
F --> G[CustomDocTestRunner / exec]
parser.py: Extracts test blocks usingasciidoctrine(withpreprocess_directives=Falseby default to ignore illustrative includes) andasciidocstring(for Python docstrings). Tracks section boundaries, parses marker attributes (test,shared,reset), and extracts named context scopes (shared="<name>"). Also statically discovers docstrings in Python source files viafind_docstrings_in_py_file.runner.py: Coordinates execution across interactive REPL blocks and script blocks. Enforces namespace scoping, section boundary resets, explicitresetdirectives, and named context state maps.docstring_extractor.py: Implements the programmatic APIsrun_adoc_testsandextract_and_run_docstring_teststo discover, extract, and execute doctests from.adocfiles,.pyfiles, directories, or loaded modules with per-symbol scope isolation.pytest_plugin.py: Discovers files statically, collects docstrings from Python modules without executing module code during discovery, and handles test execution and error formatting for pytest.unittest_integration.py: Wraps test collection and execution in standard library unittest adapters (DocFileSuiteandDocTestSuite).
Testing and Coverage
tests/test_runner.py: Tests runner mechanics and state persistence.tests/test_scoping.py: Tests named context scopes and explicit reset markers.tests/test_section_scoping.py: Tests AST section boundary resets.tests/test_parser_includes.py: Tests illustrative include directive handling (preprocess_directives=False).tests/test_docstring_extraction.py: Tests Python docstring extraction across files, directories, and modules.tests/test_api.py: Tests programmatic runner API (run_adoc_tests) andfail_fastbehavior.tests/integration/: Tests API consumer workflows and end-to-end execution patterns.tests/test_plugin.py: Validates pytest collection.tests/test_plugin_collision.py: Tests module name isolation for same-named files across directories.tests/test_plugin_coverage.py: Tests error boundaries and collection edge cases.tests/test_unittest_integration.py: Tests unittest adapters.tests/test_footnotes.py: Verifies footnote compatibility.
Development Commands
Using Hatch:
hatch run test # Run test suite with coverage
hatch run cov-report # Display coverage report
hatch run lint # Run ruff check
hatch run format # Check ruff formatting
hatch run format-fix # Apply ruff formatting
hatch run typecheck # Run mypy in strict mode
hatch run docs-build # Build Sphinx documentation
hatch run docs-serve # Serve built HTML documentation locally
Pre-Release Checklist
1. Dependency Audit
☐ Verify that constraints in
pyproject.tomlmatch expected dependency versions.☐ Verify that
pylock.tomlis up to date.
2. Code Quality and Style
3. Verification Suite
☐ Run the test suite:
hatch run test
☐ Verify code coverage meets the 97% requirement:
hatch run cov-report
4. Documentation Check
☐ Confirm that examples in
README.adocand documentation files pass during test execution.☐ Review
SECURITY.adocanddocs/security.adocto ensure supported versions and reporting guidelines are current.☐ Update
CHANGELOG.adocanddocs/changelog.adocwith release notes for the target version.
5. Publishing Preparation
☐ Update the
versionfield inpyproject.toml.☐ Build distribution packages:
python -m build