Closed sscherfke closed 1 year ago
{doctest}
directive, you need to include the doctest
extension in your conf.py
:extensions = [
"myst_parser",
"sphinx.ext.doctest",
]
Let me know if this works for you, if it does, I'll close this issue and cut a release for the #44 fix :-)
I’ll see if I can get away with not using the Doctest parser and only use the PythonCodeBlock parser.
Anyways, I think that the docs should be updated to avoid confusion:
python
code blockBoth issues apply to rest documents, too.
And thansk for the quick response. Appart from this issue, Sybil is realy awesome :)
Both issues apply to rest documents, too.
Oh? Can you give me an example?
Test
====
1
-
::
>>> print(2)
1
2
-
.. code-block:: python
>>> print(2)
2
from doctest import ELLIPSIS
from sybil import Sybil
from sybil.parsers.rest import DocTestParser, PythonCodeBlockParser
pytest_collect_file = Sybil(
parsers=[
DocTestParser(optionflags=ELLIPSIS),
PythonCodeBlockParser(),
],
patterns=["*.rst"],
).pytest()
E ValueError: <Region start=45 end=93 <bound method PythonCodeBlockParser.evaluate of <conftest.PythonCod
eBlockParser object at 0x105abaec0>>> from line 15, column 1 to line 20, column 1 overlaps <Region start=69
end=92 <sybil.evaluators.doctest.DocTestEvaluator object at 0x105abad70>> from line 17, column 1 to line 1
9, column 1
And to use .. doctest
, you still need the corresponding extension in your conf.py
:)
Okay, the overlap check is doing its job there. You should not put doctest examples inside a .. code-block:: python
, I'll put a note in the docs.
I've also added notes highlighting that you need to enable the doctest extension to use those directives.
I'll close this issue out now, feel free to re-open / comment if you feel there's more to, open a new issue if it's not related to the stuff above.
Point 4 is still an issue if you use the DocTestParser
with markdown documents:
If I only use the DocTestParser, all four examples are collected, but doctest considers the closing three backticks as part of the example and fails with sth. like 1\n''' != 1`.
In mardown documents, the following snippet:
print(3) 3
would result in the assertion
assert "3\n```" == "3"
which will fail.
What happens if you do:
print(3) 3
?
Then the test passes, but I get an empty, ugly extra line when rendering the docs:
🤪
I guess use one of the other parser options then...
The thing is, that the doctestparser does not recognize codeblocks but only looks for >>>
and the corresponding output lines.
Doctest examples are even collected when they are not fenced. But they are then not render correctly.
It's the ReST doctest parser, it's there as a "may work for you" thing, the docs clearly introduce better alternatives before hand, so I'd suggest using one of them.
I try to use Sybil with a Markdown file that contains normal Python code block and doctests.
Testing doctests does not work in several ways though and I am not sure whether I am doing something wrong, or whether there is a (documentation) issue in Sybil.
I am using:
Minimal example
docs/index.md
2
3
4
conftest.py
Problems
{doctest}
directive and will not show it, but the docs state otherwisePythonCodeBlockParser
, only examples 2 and 3 are collected, but sucessfully testedDocTestDirectiveParser
, only example 4 is collected, but successfully tested. But it leads to Sphinx errors (see 1.).DocTestParser
, all four examples are collected, but doctest considers the closing three backticks as part of the example and fails with sth. like1\n'''
!= 1`.DocTestParser
andPythonCodeBlockParser
(which I'd like to do in my real project, Sybil fails because of overlapping regions. I can "fix" this by removing thepython
/{code-block} python
from examples 2 and 3, but then I get the same error as in point 4. again.