Skip to main content

A pytest plugin to doctest your markdown files

Project description

pytest-markdoctest

PyPI version Python versions

A pytest plugin to doctest your markdown files.

Help you test your python blocks in markdown in doctest style, and make sure them behaving as you expected. This is especially helpful when dealing with markdown files containing many demo code, such as

  • A project documented in markdown files,
  • A tutorial on python written in markdown.

Requirements

  • python>=3.7
  • pytest>=6

Installation

You can install "pytest-markdoctest" via pip from PyPI:

$ pip install pytest-markdoctest

Usage

To test a single markdown file:

$ pytest docs/index.md

or test all markdown files in a directory:

$ pytest docs/

Your markdown file may contains REPL block (Read-Eval-Print-Loop).

>>> 2 + 3
5
>>> print("Hello World!")
Hello World!

Or script block.

import math
def square(x):
    return x*x

Variables/functions defined before are accessible in subsequent blocks.

>>> math.pow(2, 2)
4.0
>>> square(2)
4

Markdoctest automatically find all code blocks tagged by python, py, pycon and test them.

Directives are allowed to control testing behavior.

<!-- doctest: +SKIP -->
```python
import math
a = 3 / 0
```

Advanced Usage

License

Distributed under the terms of the MIT license, "pytest-markdoctest" is free and open source software

Acknowledgement

This pytest plugin was generated with Cookiecutter along with @hackebrot's cookiecutter-pytest-plugin template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-markdoctest-0.1.0.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

pytest_markdoctest-0.1.0-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page