Skip to main content

pytest plugin to test codeblocks in your documentation.

Project description


Build Status PyPI Downloads License

pytest plugin to test code sections in your documentation.


pip install pytest_docfiles


Define code sections in your markdown files.

<!-- -->
# Hello World
print("hello world!")

run pytest on your markdown files with the --docfiles flag.

pytest --docfiles


Section Names

Define names for your code sections so they can be better identified in your pytest output

<!-- -->
```python {"name": "my-section"}
print("hello world")
$ pytest --docfiles


Define your fixtures in as usual


import pytest

def custom_fixture() -> str:
    return "fixture value"

def autouse() -> None:
    """autouse fixtures are used in each code section"""

use the fixtures in your code sections

<!-- -->
```python {"fixtures": ["custom_fixture"]}
assert custom_fixture == "fixture value"


Code section depending on other code section can be executed in scopes.

```python {"scope": "my-scope"}
value = True
```python {"scope": "my-scope"}
assert value is True

Skip Sections

```python {"skip": true}
raise Exception("this section should not run")

Exception Handling

```python {"raises": "RuntimeError"}
raise RuntimeError("this section should pass")

Project details

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pytest_docfiles-0.2.0-py3-none-any.whl (5.3 kB view hashes)

Uploaded py3

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