3 ms·
> - Example sections will be cluttered with unit tests. The fundamental purpose of doctests is not to write unit tests, but to ensure your examples are valid.
by masklinn 4y ago
> - Example sections will be cluttered with unit tests.
The fundamental purpose of doctests is not to write unit tests, but to ensure your examples are valid. It's easy to write examples which don't work in docstrings.
Running a doctest system on your documentation doesn't preclude having actual tests, quite the opposite. Edge cases or complicated scenarios often don't make for great examples, but are usually valuable tests.
For instance in Rust most methods of Vec have an example, which is doctested, and yet Vec still has an extensive suite of unit tests: https://github.com/rust-lang/rust/blob/master/library/alloc/tests/vec.rs https://github.com/rust-lang/rust/blob/master/library/alloc/...
Technically you could use doctests as a literate-ish test framework (assuming that's even supported, which it may not be), but the oddball environment tends to make that not great, and the "literate" part is not very useful when unit testing. It's way more valuable to ensure docstrings and standalone documentation are valid.
- apwheele 4y agoYeah, and the R ecosystem has this built in (checking the examples run, not their output is correct). `R CMD check` has as one of its checks whether the examples you build in the help docs generate runtime errors. I use roxygen example help file generation as well for R packages, but have mixed feelings relative to python documentation.