-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doctest SKIP directive ignored by testcode:: code block #13103
Comments
Thanks for the report @cacti77 - I could be mistaken, but I think there are two things to note here:
.. testcode::
:options: +SKIP
x = 10
x += 10
print(x)
.. testoutput::
10 This should skip the test, meaning that it won't contribute towards failing the build despite the possibility (actuality, in this case) that the in it fails to evaluate to the expected output. I think we should update the Sphinx documentation to clarify the latter point. |
That was also my impression, although the Python docs state it clearly the way it's phrased still leaves margin for doubt. |
@jayaddison : ok, you're right, I misunderstood. I thought It would be really useful to have a feature that allows the skipping of specific lines within an example, because then I could show code in examples but skip running certain lines that might cause a problem in doctest; like popping up matplotlib plots that can't be closed without user intervention, for example. However you'd also need a way of suppressing those flags from being shown in other builders (like html). The bit that misled me in the docs was where it says:
for the |
Thanks @cacti77. It seems I spoke too soon; after some more experimentation with The additional context from your comment is useful too; if I understand it, the goal is to produce documentation that contains example code users can read and run for themselves, and also to run that code during project builds, to ensure that it continues to produce the expected results/output. Edit: insert some missing/clarifying words |
(...and for the sample code that is presented in the documentation to omit any irrelevant doctest-configuration comments) |
Ok, yep - I think we have a bug here somewhere. It could perhaps relate to the difference between the I'm able to get the following to pass: .. doctest::
>>> x = 10
>>> x += 10 # doctest: +SKIP
>>> print(x)
10 But this fails (as reported): .. testcode::
x = 10
x += 10 # doctest: +SKIP
print(x)
.. testoutput::
10 |
@cacti77 A short summary / tl;dr here is that if you can refactor to use the NotesThere are some implementation details of the In particular: the behaviour here stems from the fact that When a
...or potentially something about the difference in the way that the |
@jayaddison - thanks for all the comments. I'm glad doctest independently of Sphinx can skip individual lines of code. That's what I would expect if it is permissible to add Given that behaviour in doctest then I don't understand why you say this:
Surely the intention should be to apply the same behaviour as in doctest - i.e., only ignore specific lines appended with
Thanks! But for the rst tutorial docs I think the |
If you can spare the time this would be worth an FR at the CPython repository, I find the: ",do not run the example at all." clause very misleading and prone to confusion. |
@electric-coder (Err, what's an FR?!) This sentence in doctest.SKIP threw me too:
However, the doctest docs as a whole suggest an 'example' corresponds to a single interactive prompt. E.g., in this code snippet:
there are 3 prompts and hence 3 'examples', each of which could be appended by their own doctest directive (such as If this interpretation is correct then it makes sense to support doctest directives on individual lines in doctest blocks, because that would be consistent with doctest itself. It comes back to this comment by @jayaddison. Does sphinx.ext.doctest support doctest directives at the per line level for doctest-style code blocks, but only apply them at the level of the whole code block for code-output-style blocks? This is what happens now, but maybe an exception should also be thrown if any doctest directives are detected on lines within Or take the easy route out: leave it as it is, but maybe change the docs for |
Describe the bug
doctest is ignoring the +SKIP directive in my rst testcode:: samples.
How to Reproduce
The docs at https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html#directive-testcode imply that I can append doctest directives to the end of a line in a code sample. However they don't appear to be honoured.
Simple example from an rst file:
But
make doctest
fails with:It's clearly running the line it should be skipping. At first I thought the default
trim-doctest-flags
flag was effectively stripping out the doctest directive before obeying it. But setting the:no-trim-doctest-flags:
option fortestcode::
doesn't change the result.I've only tried the SKIP directive, but it's possible this issue applies to other doctest directives too.
Environment Information
Sphinx extensions
My
conf.py
has these extensions:Additional context
No response
The text was updated successfully, but these errors were encountered: