reStructuredText input format
reStructuredText (RST) is the markup language of Sphinx and docutils projects. Doc Detective reads inline tests from RST comments and detects steps from RST syntax, with no configuration. Doc Detective parses RST itself, so you don’t need Sphinx or docutils installed.
File extensions
Doc Detective processes reStructuredText files with the .rst extension.
To read files with another extension as RST, add a file type that extends rst to fileTypes in your config file:
The extension picks the parser, so a .rst file always parses as RST, even in a file type that extends markdown.
A fileTypes list in your config replaces the default list. If your config already sets fileTypes, add "rst" to it to keep reading .rst files.
Inline test syntax
RST files use comments for inline tests. Put a blank line before and after each statement:
Test start:
Step:
Test end:
Ignore blocks:
A comment holds its first line plus the indented block below it, so a long step can continue on the next lines:
Only comments hold statements. Directives (.. note::), hyperlink targets (.. _name:), footnotes (.. [1]), citations (.. [name]), and substitution definitions (.. |name|) aren’t comments.
Example
Here’s a complete example of an RST file with inline tests:
Detected tests
With step detection on, RST files detect the steps listed in What gets detected, from RST syntax:
A screenshot image’s source is the file to save:
To show a command without running it, add :class: testIgnore:
A literal block is the indented block after a paragraph that ends in ::. It has no language.
Comments, links, and formatting inside code blocks, literal blocks, inline literals (``text``), interpreted text and roles (:guilabel:`Save`), and raw directives aren’t read. In other directives, such as note and warning, the body is prose, but the text on the directive’s own line isn’t read.
Doc Detective reads links whose URL sits inside the link, as in `text <https://example.com>`_. To make a link detectable, write it that way rather than as a named reference to a .. _name: url target.
Because roles aren’t read, a UI label written as :guilabel:`Save` doesn’t become a step. To act on it, add a step, such as .. step {"click": "Save"}. To change what’s detected, see Selectors and custom inputs.
JSON and YAML syntax
RST inline tests support both JSON and YAML syntax:
JSON syntax:
YAML syntax:
Both formats work identically. Choose the format that’s most readable for your team.
Best practices
- Put a blank line before and after each statement. A
..line that continues a paragraph is prose, not a comment. - Use descriptive test IDs to identify tests in results.
- Write each link with its URL inside it, as in
`text <https://example.com>`_, so Doc Detective detects it. - Combine inline tests with detected tests so links, bold text, and code blocks become steps without extra comments.
Includes
Doc Detective resolves .. include:: directives before it finds tests, so a test in an included file runs inside the page that includes it. It supports :start-line:, :end-line:, :start-after:, :end-before:, and / paths from the folder that holds conf.py. An included file doesn’t run on its own. See Test pages that include other files.
Effect on your build
RST test comments are standard RST comments, so Sphinx and docutils leave them out of the rendered output. Your build doesn’t change, and the tests stay in the source.
”Last verified on” dates
Doc Detective doesn’t write verification results into .rst files, and it skips them without a warning. In an RST file, a verified-by entry, a meta statement, and badge: true on a test statement have no effect, and verification.write leaves the file unchanged.
To record when an RST test last passed, give it a testId and name that ID in a verified-by entry on a page in another format. See Show a “Last verified on” date.
Next steps
- Learn about inline tests for manual test definition.
- See custom inputs to add detected test patterns for RST.
- See Detected tests for how step detection works across formats.