Skip to content

Enable embedding tests/tasks to Markdown files #5603 - #5633

Merged
pekkaklarck merged 13 commits into
robotframework:masterfrom
seto:feat/markdown-tests-support
Apr 21, 2026
Merged

pekkaklarck merged 13 commits into
robotframework:masterfrom
seto:feat/markdown-tests-support

Conversation

@seto

@seto seto commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

This pull request introduces support for parsing test data and resource files written in Markdown format (.md, .markdown, .robot.md) in addition to the existing formats. It adds new parser logic, updates file extension handling throughout the codebase, and provides comprehensive acceptance tests to ensure correct behavior for Markdown files.

Markdown file format support

  • Added a new MarkdownParser class in parsers.py to handle .md, .markdown, and .robot.md files, utilizing the read_markdown_data utility private method _read_markdown_data inside MarkdownParser for parsing.
  • Updated builder logic to recognize and use MarkdownParser for Markdown file extensions in both test suite and resource file parsing.
  • Extended the list of supported extensions in settings and suite structure builder to include .robot.md.

Acceptance and Unit tests for Markdown support

  • Added new acceptance test suites and sample files under atest/testdata/parsing/data_formats/markdown/ to verify correct parsing, error reporting, and suite structure for Markdown files, including edge cases and directory handling.
  • Added Markdown resource files and updated resource extension tests to validate that .md and .markdown resources are parsed and imported correctly.
  • Updated test cases and data format references to account for the new Markdown extensions and increased test counts accordingly.
  • Added utest/parsing/test_markdownreader.py utest/parsing/test_markdownparser.py to validate the state-machine logic and edge cases (empty blocks, unclosed fences, etc.).

These changes ensure that Robot Framework can now seamlessly parse and execute tests and resources written in Markdown, with robust test coverage for the new functionality.

@seto seto changed the title Enable embeddding tests/tasks to Markdown files #5603 Enable embedding tests/tasks to Markdown files #5603 Mar 23, 2026
@pekkaklarck

Copy link
Copy Markdown
Member

Thanks for the PR! I don't have time for a proper review now, but based on a quick look at the implementation I have one request. Could you move the code related to reading Markdown data from robot.utils to robot.running.builder? The code is pretty simple, so it could possibly be made part of the new MarkdownParser class, but having that part in a separate module is fine as well.

I know there's read_rest_data under robot.utils and that I had instructed in the original issue to use the reStructuredText parser as an example. I had forgotten part of that implementation is under robot.utils and, more importantly, I don't see any good reasons why it's there. I guess part of the reason is to have conditional docutils imports in a separate module, but even then I see no reason to have that functionality under robot.utils when it's only used exactly once in parsing. Either there has been some good reason for this earlier or we just made a bad decision earlier. Anyway, let's not add the Markdown reading code under robot.utils. I'll separately consider deprecating robot.utils.read_rest_data and moving the related code elsewhere.

@seto

seto commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

Hello Pekka, thanks for the quick look!
Ok, makes sense. I'll move the reading logic into MarkdownParser class and clean up robot.utils right away.
I'll ping you once the PR is updated.

@seto

seto commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

Refactoring complete!

Moved the Markdown reading logic into MarkdownParser and cleaned up robot.utils as discussed. Unit tests have been updated and moved to reflect the new architecture.

All utest and atest are passing locally. Let me know if it looks good to you!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds Markdown (.md, .markdown, .robot.md) as a supported data format for Robot Framework suite/resource parsing, updating extension handling across runtime builder/import logic and introducing acceptance + unit coverage for the new behavior.

Changes:

  • Introduces MarkdownParser to extract Robot Framework fenced code blocks from Markdown sources.
  • Extends suite/resource extension handling to recognize Markdown-based files (including .robot.md by default for suites).
  • Adds acceptance test data and test cases covering Markdown parsing, resource importing, and CLI/extension behaviors.

Reviewed changes

Copilot reviewed 20 out of 22 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
utest/running/test_markdownparser.py Unit tests for Markdown fenced-block extraction logic.
src/robot/running/importer.py Allows .md/.markdown as valid resource file extensions.
src/robot/running/builder/parsers.py Adds MarkdownParser implementation for extracting Robot data from Markdown fences.
src/robot/running/builder/builders.py Wires MarkdownParser into suite/resource builder parser selection and extension mapping.
src/robot/parsing/suitestructure.py Adds .robot.md to default suite structure extensions.
src/robot/conf/settings.py Adds .robot.md to default CLI --extension setting.
atest/testdata/parsing/data_formats/resources/markdown_resource.md New Markdown resource test data.
atest/testdata/parsing/data_formats/resource_extensions/tests.robot Extends resource extension test to include .md/.markdown.
atest/testdata/parsing/data_formats/resource_extensions/resource.md New Markdown resource file test data (.md).
atest/testdata/parsing/data_formats/resource_extensions/resource.markdown New Markdown resource file test data (.markdown).
atest/testdata/parsing/data_formats/markdown/with_init/sub_suite2.robot.md New .robot.md suite test data.
atest/testdata/parsing/data_formats/markdown/with_init/sub_suite1.MD New uppercase .MD suite test data.
atest/testdata/parsing/data_formats/markdown/with_init/init.md New Markdown init file test data.
atest/testdata/parsing/data_formats/markdown/sample.md Comprehensive Markdown suite sample with multiple robot blocks + ignored content.
atest/testdata/parsing/data_formats/markdown/invalid.markdown Markdown file with no robot blocks for “no tests/tasks” behavior.
atest/robot/parsing/data_formats/resource_extensions.robot Updates expected supported extensions and line references for resource extension tests.
atest/robot/parsing/data_formats/markdown.robot New acceptance tests validating Markdown parsing, directory behavior, and error sources.
atest/robot/parsing/data_formats/formats_resource.robot Adds ${MARKDOWN DIR} used by new Markdown acceptance tests.
atest/robot/cli/runner/included_files.robot Updates expected counts/line refs impacted by added parsing test coverage.
atest/robot/cli/runner/extension.robot Updates expected counts/line refs impacted by new Markdown-related coverage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/robot/running/builder/parsers.py Resolved
Comment thread src/robot/running/builder/parsers.py Resolved

@pekkaklarck pekkaklarck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only reviewed the code changes now. They look good in general and most of my comments were somewhat nitpickey. We do need to think about detecting starting code blocks, though, but I'll comment the original issue about that.

Comment thread src/robot/running/builder/parsers.py Resolved
Comment thread src/robot/running/builder/parsers.py Resolved
Comment thread src/robot/running/builder/parsers.py Resolved
Comment thread src/robot/running/builder/parsers.py Resolved
seto added 12 commits March 27, 2026 19:16
…tframework#5603)

- Added .robot.md to default extensions in RobotSettings.
- Registered MarkdownParser in TestSuiteBuilder and ResourceFileBuilder.
- Updated SuiteStructureBuilder to recognize Markdown files.
- Added read_markdown_data to robot.utils and a placeholder in markdownreader.
- Added .md and .markdown to RESOURCE_EXTENSIONS in Importer.
…otframework#5603)

- Integrated a new MarkdownParser using a lightweight FSM.
- Added support for both ```robotframework and ```robot code blocks.
- Implemented line-synchronization logic by preserving empty lines for non-robot content, ensuring accurate error reporting.
…#5603)

- Followed the existing reStructuredText (RST) test structure to ensure parity.
- Added test cases for parsing suites from .md and .robot.md files.
…#5603)

- Reverted vertical formatting for included_extensions to maintain horizontal density.
…code blocks

- Updated unit tests to cover related edge cases.
…amework#5603)

- Use Regex for code fence detection (supports ``` and ~~~).
- Handle variable fence lengths and info strings.
- Use textwrap.dedent for robust indentation management.
- Remove redundant string stripping and pending separators.
Copilot AI review requested due to automatic review settings March 27, 2026 18:27
@seto
seto force-pushed the feat/markdown-tests-support branch from ccfcd7c to c530937 Compare March 27, 2026 18:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 21 out of 23 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/robot/running/builder/builders.py Resolved
@seto

seto commented Mar 27, 2026

Copy link
Copy Markdown
Contributor Author

I've updated the PR with the following changes:

  • Regex-based detection: Refactored the logic to support backticks, tildes, variable fence lengths, and info strings.
  • Unclosed fences: The parser will consume everything until EOF if the closing fence is missing, assuming we will strictly follow the CommonMark spec.
  • Indentation: Switched to textwrap.dedent for cleaner and more robust block extraction.
  • Refactoring: Removed the pending_separator and the unnecessary rstrip/strip calls during extraction to keep the logic leaner.
  • Rebase: Performed a rebase to ensure the PR is clean and up-to-date with the latest master.

All local unit tests and acceptance tests are passing on my end.

@seto
seto requested a review from pekkaklarck March 27, 2026 18:52
@pekkaklarck

Copy link
Copy Markdown
Member

I took a quick look at the code and it looks great! There are some nitpickey things that could be changed, but I believe it's best I merge this PR and do such changes myself. I also need to take a more closer look at the test.

The main thing missing seems to be documentation. It can be added after this PR is merged, but certainly needs to be done before closing #5603. Do you @seto have interest to look at the docs as well?

# ```
md = (
"```robotframework\n*** Test Cases ***\nMy Test Log Hello, RF!\n```\n"
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting input strings using triple-quoted strings like

md = """
```robotframework
*** Test Cases ***
My Test    Log    Hello, RF!

"""
would make tests easier to read and avoid the need to have the comment with same data.

@pekkaklarck

Copy link
Copy Markdown
Member

Tests look great as well! It seems you used acceptance tests for other formats as a base which is great for consistency and maintainability. The only thing that I noticed that could/should be changed is how input data is formatted with unit tests. I can do that after I've merged this PR along with small code changes.

@pekkaklarck
pekkaklarck merged commit 6f372ad into robotframework:master Apr 21, 2026
8 checks passed
@seto
seto deleted the feat/markdown-tests-support branch April 22, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants