Skip to main content

Pytest plugin for runs tests directly from Markdown files

Project description

markdown-pytest

Pytest plugin for running tests directly from Markdown files.

Markdown:

<!-- name: test_assert_true -->
```python
assert True
```
Will be shown as
assert True

This module parsed code by these rules:

  • Code without <!-- name: test_name --> comment will not be executed.
  • Allowed two or three dashes in the comment symbols
  • Code blocks with same names will be merged in one code and executed once

Code split

You can split test to the multiple blocks with the same test name:

Markdown:

This block performs import:

<!-- name: test_example -->
```python
from itertools import chain
```

`chain` usage example:

<!-- name: test_example -->
```python
assert list(chain(range(2), range(2))) == [0, 1, 0, 1]
```
Will be shown as

This block performs import:

from itertools import chain

chain usage example:

assert list(chain(range(2), range(2))) == [0, 1, 0, 1]

Fictional Code Examples

Code without <!-- name: test_name --> comment will not be executed.

```python
from universe import antigravity, WrongPlanet

try:
    antigravity()
except WrongPlanet:
    print("You are on the wrong planet.")
    exit(1)
```
Will be shown as
from universe import antigravity, WrongPlanet

try:
    antigravity()
except WrongPlanet:
    print("You are on the wrong planet.")
    exit(1)

Usage example

This README.md file might be tested like this:

$ pytest -v README.md
======================= test session starts =======================
platform darwin -- Python 3.10.2, pytest-7.2.0, pluggy-1.0.0
plugins: markdown-pytest-0.1.0
collected 2 items

README.md::test_assert_true PASSED                                                                                                                                                                                                     [ 50%]
README.md::test_example PASSED

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

markdown_pytest-0.2.1.tar.gz (7.7 kB view hashes)

Uploaded Source

Built Distribution

markdown_pytest-0.2.1-py3-none-any.whl (7.9 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