Post History
ReadTheDocs (a popular system for documenting code-bases) has an interesting feature which may provide an answer to this question: literalinclude. With this directive, one can include code example...
Answer
#3: Attribution notice added
Source: https://writers.stackexchange.com/a/16511 License name: CC BY-SA 3.0 License URL: https://creativecommons.org/licenses/by-sa/3.0/
#2: Initial revision
[ReadTheDocs](https://readthedocs.org/) (a popular system for documenting code-bases) has an interesting feature which may provide an answer to this question: [literalinclude](http://sphinx.readthedocs.org/en/latest/markup/code.html#includes). With this directive, one can include code examples from another file within the documentation. The particularly interesting part is that a subset of lines can be extracted from the source file via the `:lines:` directive meaning that the source file could be a complete (executable, testable) example while only the snippet that is relevant to the documented section need appear in the docs. Using this directive, it would theoretically be possible to include all examples in the documentation within the project's test suite. I can't say I've ever gone that far myself - but having run into this precise issue more than once I'm now tempted to give it a try!