Skip to main content

Test code blocks in your READMEs

Project description

meshio

Test code blocks in your READMEs.

PyPi Version Anaconda Cloud PyPI pyversions GitHub stars PyPi downloads

gh-actions codecov LGTM Code style: black

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.

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.

License

This software is published under the MIT license.

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

pytest-codeblocks-0.11.2.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

pytest_codeblocks-0.11.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file pytest-codeblocks-0.11.2.tar.gz.

File metadata

  • Download URL: pytest-codeblocks-0.11.2.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for pytest-codeblocks-0.11.2.tar.gz
Algorithm Hash digest
SHA256 f0c7117cf992a3424bf363917ea8a9b9b3b39c0f9a24479751db765e5064ec77
MD5 4f7f9d1b5383a9101214552fc459546f
BLAKE2b-256 26534e30edb962d4aef39eb8eb2b4e99fe03e8b63327ba8332f6674ff577fc61

See more details on using hashes here.

File details

Details for the file pytest_codeblocks-0.11.2-py3-none-any.whl.

File metadata

  • Download URL: pytest_codeblocks-0.11.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for pytest_codeblocks-0.11.2-py3-none-any.whl
Algorithm Hash digest
SHA256 de69d432525ef6b6dd1547a71f0bc9350f5392a50f43c8ebfbb110d4d4c48787
MD5 5f63a8ed4cf1b173975a0475a9b201f6
BLAKE2b-256 4865ceefcff435fc0bb07591a82644816d18d9f0d27680101be6d4cca823c4d5

See more details on using hashes here.

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