Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python: doctest my github-markdown files?

I'd like to run the doctests from this file, and it's not clear to me out to accomplish it:

README.md:

# WELCOME!

This library is helpful and will help you in _many_ ways!

For example:

```
>>> import library
>>> library.helps()
True
```

(aside: can anyone help me get this to highlight as markdown?)

like image 972
bukzor Avatar asked Apr 23 '14 16:04

bukzor


People also ask

How do I run a doctest file in Python?

You can instruct the Python interpreter to run the doctest module directly from the standard library and pass the file name (s) on the command line: python -m doctest -v example.txt. Because the file name does not end with .py, doctest infers that it must be run with testfile (), not testmod ().

How to write docstrings in Markdown?

A thing to note: The docstrings ought to be written in restructuredtext (RST). If they are in Markdown, you need to add a mod - see this. The two are similar, but different. For example, a single backquote is required for <code> in Markdown, while two are for RST.

What is doctestfailure in Python?

DocTestFailure defines the following attributes: The DocTest object that was being run when the example failed. The Example that failed. The example’s actual output. exception doctest.

What is mkdocs in Python?

MkDocs is a Python package that allows you to build static pages using Markdown. The basic structure of an MkDocs project consists of three main components: You already have your project code ready to go. Create the other two puzzle pieces next using the handy new command provided by MkDocs:


Video Answer


1 Answers

As an alternative to doctest I wrote mkcodes, a script that pulls code blocks out of markdown files so they can be tested in a separate file.

Here's my actual test script using mkcodes:

mkcodes --github --output tests/docs/test_{name}.py docs
py.test tests
pyflakes tests
pep8 tests
like image 128
Ryne Everett Avatar answered Nov 15 '22 17:11

Ryne Everett