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 8, 2022
1 parent 0aefca0 commit 77e116d
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions tests/test_sphinx_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __call__(
must_raise: bool = False,
file_type: str = "rst",
sphinxopts: Optional[List[str]] = None,
):
) -> str:
index_rst = self.tmp_path / "source" / "index.rst"
index_file = self.tmp_path / "source" / f"index.{file_type}"
file_content = textwrap.dedent(file_content)
Expand Down Expand Up @@ -142,19 +142,52 @@ def test_testcode(
plugin_result = testdir.runpytest("--doctest-glob=index.rst").stdout
plugin_result.fnmatch_lines(["*=== 1 passed in *"])

def test_doctest(
self, testdir: Testdir, sphinx_tester: SphinxDoctestRunner
) -> None:
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: Testdir,
sphinx_tester: SphinxDoctestRunner,
file_type: str,
code: str,
) -> None:
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(
Expand Down

0 comments on commit 77e116d

Please sign in to comment.