Sphinx wouldn't be the one to run the lines. But the doctest module does support running doctests embedded in prose documentation. By extension py.test supports this as well.  Where Astropy is concerned I just need to figure out how to make the correct tweaks needed to point to the right documentation location while ignoring auto-generated module docs. It also needs a way to mark docstring-like strings as non-tests.

In other words, it's possible currently. But to use the feature well might take a little tinkering.