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. It supports Python and shell code.
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.11.0
collected 56 items
example.md ....................... [ 50%]
README.md ....................... [100%]
================================= 56 passed in 0.08s ==================================
pytest-codeblocks will only pick up code blocks with python and sh/bash/zsh
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.
Conditionally skipping code blocks works with skipif, e.g.,
<!--pytest-codeblocks:skipif(sys.version_info <= (3, 7))-->
You can also skip all blocks in the entire file by putting
<!--pytest-codeblocks:skipfile-->
in the first line.
Merging code blocks
Broken-up code blocks can be merged into one with the pytest-codeblocks:cont prefix
Lorem ipsum
```python
a = 1
```
dolor sit amet
<!--pytest-codeblocks:cont-->
```python
# this would otherwise fail since `a` is not defined
a + 1
```
If you'd like to prepend code that you don't want to show, you can just comment it out; pytest-codeblocks will pick it up anyway:
Lorem ipsum
<!--
```python
a = 1
```
-->
dolor sit amet
<!--pytest-codeblocks:cont-->
```python
# 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
```sh
print(1 + 3)
```
gives
<!--pytest-codeblocks:expected-output-->
```
4
```
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.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest-codeblocks-0.12.1.tar.gz.
File metadata
- Download URL: pytest-codeblocks-0.12.1.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ade20df869ec74e515eb7abb3e11d9479db4dbe9200379f8adf0af579d07fe2
|
|
| MD5 |
3d2714bda3afd8a5e4141ac6b5724693
|
|
| BLAKE2b-256 |
e36011b97e6f7661360bdc44bf3dd501ebea1a56a3cb4d97b43f463d864cd5d2
|
File details
Details for the file pytest_codeblocks-0.12.1-py3-none-any.whl.
File metadata
- Download URL: pytest_codeblocks-0.12.1-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0665629b73905fd23a9bc852eb1c8497e716292e64a55f541a56726ad07eff2
|
|
| MD5 |
44497d82975f89304220be00debfbd95
|
|
| BLAKE2b-256 |
30fb86b75568d538c82b5cd32c994b6c77f220231eeb8220494dde7d2359f844
|