pytest_docfiles
pytest plugin to test code sections in your documentation.
Installation
pip install pytest_docfiles
Usage
Define code sections in your markdown files.
<!-- doc.md -->
# Hello World
```python
print("hello world!")
```
run pytest on your markdown files with the --docfiles flag.
pytest --docfiles doc.md
Features
Section Names
Define names for your code sections so they can be better identified in your pytest output
<!-- doc.md -->
```python {"name": "my-section"}
print("hello world")
```
$ pytest --docfiles doc.md
...
doc.md::my-section PASSED
...
Fixtures
Define your fixtures in conftest.py as usual
# conftest.py
import pytest
@pytest.fixture
def custom_fixture() -> str:
return "fixture value"
@pytest.fixture(autouse=True)
def autouse() -> None:
"""autouse fixtures are used in each code section"""
use the fixtures in your code sections
<!-- doc.md -->
```python {"fixtures": ["custom_fixture"]}
assert custom_fixture == "fixture value"
```
Scopes
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")
```
Release files for pytest-docfiles 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_docfiles-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / pytest_docfiles-0.2.0-py3-none-any.whl
| Download URL | pytest_docfiles-0.2.0-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
396536c79a8c895f3743c8ebd765bcb827f0c2d276de0e3e3a53e66b9403b7e1
|
|
BLAKE2b-256 checksum How to use checksums |
973f5c6fc7f295c45eefb2ceb381803b56e4f0be5de6ba743948741a241dfba9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
|