Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/pytest_markdown_docs/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class FenceTestDefinition:
source_path: pathlib.Path
runner_name: typing.Optional[str]
max_retries: int = 0
# All options on the fence (everything after the language in the info
# string, plus any mdx-comment metadata), including ones the plugin itself
# consumes, e.g. `fixture:foo` and `continuation`. Lets custom runners
# define their own options without requiring a pytest fixture per flag.
options: typing.FrozenSet[str] = frozenset()


@dataclass(frozen=True)
Expand Down
1 change: 1 addition & 0 deletions src/pytest_markdown_docs/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def extract_fence_tests(
source_path=source_path,
runner_name=runner_name,
max_retries=max_retries,
options=frozenset(code_options),
)
prev = code_block

Expand Down
24 changes: 24 additions & 0 deletions tests/plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,30 @@ def runtest(self, test, args):
)


def test_runner_receives_fence_options(testdir):
testdir.makeconftest(
"""
import pytest_markdown_docs._runners

@pytest_markdown_docs._runners.register_runner()
class OptionsChecker(pytest_markdown_docs._runners.DefaultRunner):
def runtest(self, test, args):
assert test.options == {"runner:OptionsChecker", "my_flag", "other:value"}
"""
)
testdir.makefile(
".md",
"""
```python runner:OptionsChecker my_flag other:value
pass
```
""",
)

result = testdir.runpytest("-v", "--markdown-docs")
result.assert_outcomes(passed=1)


def test_non_python_fence_without_runner_is_ignored(testdir):
testdir.makefile(
".md",
Expand Down
Loading