I put the code in separate files from the reST and then use cog with sphinx to
run the scripts and insert the output. That lets me commit the output to source
control with the rest of the document, to catch changes between builds (I found
a regression in a Python standard library module that way
My book is structured like a tutorial, so each code example in the book
builds on the last -- they don't stand alone. the book also contains lots
of listings showing commands to run and expected output.
So my test suite works by reading the book as HTML (I prefer that, helps
catch any mistakes i