Sphinx Doctest: test the code without comparing the output.

Luca Cerone luca.cerone at gmail.com
Sat Sep 21 08:44:09 EDT 2013


Dear Steven,
thanks for the help.

I am aware that I might have used the SKIP directive (as I hinted in my mail).
Even if the fine manual suggests to do so I don't agree with it, though.
The reason is simple: SKIP as the name suggests causes the code not to be run at all, it doesn't ignore the output. If you use a SKIP directive on code that contains a typo, or maybe you changed
the name of a keyword to make it more meaningful and forgot to update your docstring, then the error won't be caught.

For example:

.. doctest:: example

   >>> printt "Hello, World!" # doctest: +SKIP
   "Hello, World!"

would pass the test. Since I am writing a tutorial for people that have even less experience than me with Python, I want be sure that the code in my examples runs just fine.

> 
> (There's no need to convert things to str before printing them.)
>

You are right, I modified an example that uses x in one of my functions that requires a string in input, and didn't change that.

Thanks again for the help anyway,

Cheers,
Luca



More information about the Python-list mailing list