Inspired by the new Markdown-based testing framework added to Ruff, I wrote up some notes on "literate testing", including trying out a pytest plugin called pytest-markdown-docs https://simonwillison.net/2024/Oct/16/markdown-test-framework/
Inspired by the new Markdown-based testing framework added to Ruff, I wrote up some notes on "literate testing", including trying out a pytest plugin called pytest-markdown-docs https://simonwillison.net/2024/Oct/16/markdown-test-framework/ 7 comments
@simon This would be useful for testing course materials I create. I like that pytest-markdown-docs seem to have thought about continuing examples, fixtures, etc. Very cool. @simon Yeah, I've used the doctest.testfile approach for longer tests *and* to reduce complaints about the doctests "cluttering" the main source code (to be fair, this also reduces friction against including much more thorough tests, so it's a net win.) There's also an "adjacent" tool https://bitheap.org/cram/ - written in python, but it processes the markdown literal-blocks as shell commands - great for CLI testing, especially in worked-example form. @simon a coworker introduced us to https://github.com/bashup/mdsh a while ago and we've been happily using it since: https://github.com/meltano/meltano/blob/main/integration/example-library/meltano-state-s3/index.md. I used to write narrative doctests a lot: https://blog.startifact.com/posts/i-like-doctests/ I moved away from them mostly these days but it has benefits as I argue in that article. |
@simon interesting idea, thanks for sharing. 👍
You wrote:
> _"This feels like an evolution of the old Python doctest idea, except that tests are embedded directly in Markdown rather than being embedded in Python code docstrings."_
IMHO the most interesting thing about `doctest` is the possibility of having the tests in the code that they have to test, and without the proximity of the code and the test I don't see, at first, a use. 🪙🪙
Reference 👇
https://docs.python.org/3/library/doctest.html
#Python #Test #Doctest
@simon interesting idea, thanks for sharing. 👍
You wrote:
> _"This feels like an evolution of the old Python doctest idea, except that tests are embedded directly in Markdown rather than being embedded in Python code docstrings."_
IMHO the most interesting thing about `doctest` is the possibility of having the tests in the code that they have to test, and without the proximity of the code and the test I don't see, at first, a use. 🪙🪙