Sphinx Doctest: test the code without comparing the output.

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Sep 22 20:36:38 EDT 2013


On Sun, 22 Sep 2013 09:39:07 -0400, Ned Batchelder wrote:

> On 9/22/13 12:09 AM, Luca Cerone wrote:
>> Hi Chris,
>> actually my priority is to check that the code is correct. I changed
>> the syntax during the development, and I want to be sure that my
>> tutorial is up to date.
>>
>>
> If you do manage to ignore the output, how will you know that the syntax
> is correct?  The output for an incorrect syntax line will be an
> exception, which you'll ignore.  Maybe I don't know enough about the
> details of doctest.  It's always seemed incredibly limited to me.
> Essentially, it's as if you used unittest but the only assertion you're
> allowed to make is self.assertEqual(str(X), "....")

More or less :-)

Doc tests really are documentation first and tests second. That's its 
strength. If you want unit tests, you know where to find them :-)


-- 
Steven



More information about the Python-list mailing list