From a64164578724140c876f964ec17b56e8b89a6e1a Mon Sep 17 00:00:00 2001 From: confarg <280620574+confarg@users.noreply.github.com> Date: Tue, 2 Jun 2026 22:59:30 +0200 Subject: [PATCH] feat: Allow directives on commented console blocks --- README.md | 29 +++++++++++++++++++++ src/pytest_markdown_console/parsing.py | 17 ++++++++++-- tests/test_parsing.py | 36 ++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd8bcde..b2ac4d5 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,35 @@ Done. `yield` fixtures work normally — teardown runs after the block completes. +### Hidden blocks + +Wrapping a fence in an HTML comment hides it from rendered output (e.g. on GitHub) while +the plugin still finds and runs it. This is useful for setup steps that would clutter the +documentation: + +````markdown + + +```` + +To attach a directive to a hidden block, place it on the line immediately before the ` + +```` + + ### Exclude a block from testing To exclude a block from being collected as a test at all, use the `notest` directive: diff --git a/src/pytest_markdown_console/parsing.py b/src/pytest_markdown_console/parsing.py index aa6b2ce..9882bb9 100644 --- a/src/pytest_markdown_console/parsing.py +++ b/src/pytest_markdown_console/parsing.py @@ -8,6 +8,7 @@ _FENCE_OPEN = re.compile(r"^```\s*console\b", re.IGNORECASE) _FENCE_CLOSE = re.compile(r"^```\s*$") +_HTML_COMMENT_OPEN = re.compile(r"^\s*\n\n" + block = parse_blocks(source)[0] + assert block.notest is True + + +def test_bare_html_comment_opener_no_directive(): + """A bare \n" + block = parse_blocks(source)[0] + assert block.notest is False + assert block.cwd_override is None + assert block.shell is None + + +def test_directive_through_html_comment_opener_indented(): + """A directive + bare \n" + " \n" + ) + block = parse_blocks(source)[0] + assert block.notest is True