Sphinx Doctest: test the code without comparing the output.

Luca Cerone luca.cerone at gmail.com
Sat Sep 21 12:25:26 EDT 2013


> And if you ignore the output, the error won't be caught either. What's 
> 
> the difference?
> 
> >>> 1 + 1  #doctest:+IGNORE_OUTPUT  (not a real directive)
> 
> 1000
> 
> 

The difference is that in that case you want to check whether the result is correct or not, because you expect a certain result.

In my case, I don't know what the output is, nor care for the purpose of the tutorial. What I care is being sure that the command in the tutorial is correct, and up to date with the code.

If you try the following, the test will fail (because there is a typo in the code)

.. doctest:: example

   >>> printt "hello, world"

and not because the output doesn't match what you expected.

Even if the command is correct:

.. doctest:: example_2

   >>> print "hello, world"

this text will fail because doctest expects an output. I want to be able to test that the syntax is correct, the command can be run, and ignore whatever the output is.

Don't think about the specific print example, I use this just to show what the problem is, which is not what I am writing a tutorial about!

> 
> 
> So you simply can't do what you want. You can't both ignore the output of 
> 
> a doctest and have doctest report if the test fails.
> 

OK, maybe it is not possible using doctest. Is there any other way to do what I want? For example using an other Sphinx extension??



More information about the Python-list mailing list