Email or username:

Password:

Forgot your password?
Simon Willison

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 simonwillison.net/2024/Oct/16/

7 comments
Paolo Melchiorre

@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 👇
docs.python.org/3/library/doct

#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. 🪙🪙

Paul Everitt

@simon Thanks a bunch for sharing this, I hadn't seen it.

Honza Javorek

@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.

Mark Eichin

@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 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.

Martijn Faassen

@simon

I used to write narrative doctests a lot:

blog.startifact.com/posts/i-li

I moved away from them mostly these days but it has benefits as I argue in that article.

Go Up