Skip to content

Commit

Permalink
test(TestDirectives::test_doctest): myst-parser example
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Sep 5, 2022
1 parent 37a29c0 commit 7857cf0
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions tests/test_sphinx_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,46 @@ def test_testcode(self, testdir, sphinx_tester):
plugin_result = testdir.runpytest("--doctest-glob=index.rst").stdout
plugin_result.fnmatch_lines(["*=== 1 passed in *"])

def test_doctest(self, testdir, sphinx_tester):
code = """
@pytest.mark.parametrize(
"file_type,code",
[
[
"rst",
"""
.. doctest::
>>> print("msg from testcode directive")
msg from testcode directive
"""
sphinx_output = sphinx_tester(code)
""",
],
[
"md",
"""
```{eval-rst}
.. doctest::
>>> print("msg from testcode directive")
msg from testcode directive
```
""".strip(),
],
],
)
def test_doctest(self, testdir, sphinx_tester, file_type: str, code: str):
if file_type == "md": # Skip if no myst-parser
pytest.importorskip("myst_parser")
sphinx_output = sphinx_tester(
code,
file_type=file_type,
sphinxopts=None
if file_type == "rst"
else ["-D", "extensions=myst_parser,sphinx.ext.doctest"],
)
assert "1 items passed all tests" in sphinx_output

plugin_result = testdir.runpytest("--doctest-glob=index.rst").stdout
plugin_result = testdir.runpytest(f"--doctest-glob=index.{file_type}").stdout
plugin_result.fnmatch_lines(["*=== 1 passed in *"])

def test_doctest_multiple(self, testdir, sphinx_tester):
Expand Down

0 comments on commit 7857cf0

Please sign in to comment.