Skip to content

Commit f2bf920

Browse files
aaazzamclaude
andcommitted
Expose fence options on FenceTestDefinition for custom runners
Custom runners previously had only fixture names as a per-fence metadata channel, forcing consumers to declare placeholder pytest fixtures for flags whose values are never used. Expose the full set of fence options (info-string options plus mdx-comment metadata) as an `options` frozenset on FenceTestDefinition so runners can define their own flags. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent e8fea98 commit f2bf920

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/pytest_markdown_docs/definitions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ class FenceTestDefinition:
1111
source_path: pathlib.Path
1212
runner_name: typing.Optional[str]
1313
max_retries: int = 0
14+
# All options on the fence (everything after the language in the info
15+
# string, plus any mdx-comment metadata), including ones the plugin itself
16+
# consumes, e.g. `fixture:foo` and `continuation`. Lets custom runners
17+
# define their own options without requiring a pytest fixture per flag.
18+
options: typing.FrozenSet[str] = frozenset()
1419

1520

1621
@dataclass(frozen=True)

src/pytest_markdown_docs/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ def extract_fence_tests(
252252
source_path=source_path,
253253
runner_name=runner_name,
254254
max_retries=max_retries,
255+
options=frozenset(code_options),
255256
)
256257
prev = code_block
257258

tests/plugin_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,30 @@ def runtest(self, test, args):
472472
)
473473

474474

475+
def test_runner_receives_fence_options(testdir):
476+
testdir.makeconftest(
477+
"""
478+
import pytest_markdown_docs._runners
479+
480+
@pytest_markdown_docs._runners.register_runner()
481+
class OptionsChecker(pytest_markdown_docs._runners.DefaultRunner):
482+
def runtest(self, test, args):
483+
assert test.options == {"runner:OptionsChecker", "my_flag", "other:value"}
484+
"""
485+
)
486+
testdir.makefile(
487+
".md",
488+
"""
489+
```python runner:OptionsChecker my_flag other:value
490+
pass
491+
```
492+
""",
493+
)
494+
495+
result = testdir.runpytest("-v", "--markdown-docs")
496+
result.assert_outcomes(passed=1)
497+
498+
475499
def test_non_python_fence_without_runner_is_ignored(testdir):
476500
testdir.makefile(
477501
".md",

0 commit comments

Comments
 (0)