Test code blocks in your READMEs
Project description
Test code blocks in your READMEs.
This is pytest-codeblocks, a pytest plugin for testing code blocks from README files.
Install with
pip install pytest-codeblocks
and run pytest with
pytest --codeblocks
================================= test session starts =================================
platform linux -- Python 3.9.4, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /path/to/directory
plugins: codeblocks-0.10.3
collected 56 items
example.md ....................... [ 50%]
README.md ....................... [100%]
================================= 56 passed in 0.08s ==================================
By default, pytest-codeblocks will only pick up code blocks with python
syntax
highlighting.
Skipping code blocks
Prefix your code block with a pytest-codeblocks:skip
comment to skip
Lorem ipsum
<!--pytest-codeblocks:skip-->
```python
foo + bar # not working
```
dolor sit amet.
Merging code blocks
Broken-up code blocks can be merged into one with the pytest-codeblocks:cont
prefix
Lorem ipsum
```
a = 1
```
dolor sit amet
<!--pytest-codeblocks:cont-->
```
# this would otherwise fail since `a` is not defined
a + 1
```
Expected output
You can also define the expected output of a code block:
This
```
print(1 + 3)
```
gives
<!--pytest-codeblocks:expected-output-->
```
5
```
Expected errors
Some code blocks are expected to give errors. You can verify this with
The following gives an error:
<!--pytest-codeblocks:expect-error-->
```python
1 / 0
```
The keyword expect-exception
is also possible.
License
This software is published under the MIT license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytest_codeblocks-0.10.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7595b4994b63abc18b1ac7d7ba196a1771f2dc8060cc15dece30eb10e7b50f46 |
|
MD5 | ca80f3f8b9708df3370d2304341f1e80 |
|
BLAKE2b-256 | 4255b7acf56452ad37e9d08bc0e86ec403449f0c2768f0b8ee01c1086950c100 |