Skip to main content

Extract code blocks from markdown

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.

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.0
collected 56 items

README.md .......................                                               [ 50%]
example.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-exception-->
```python
1 / 0
```

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.10.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

pytest_codeblocks-0.10.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest-codeblocks-0.10.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pytest-codeblocks-0.10.0.tar.gz
Algorithm Hash digest
SHA256 996c876bf43cff5b85c834fdedde709e3c758d7245b7adaf56b091cec6b95ffe
MD5 84364c9e354fc7cbfc0502668396f4f7
BLAKE2b-256 c462253ab4533d84a3a8e6cc1577197c4a17c645a6cb88db5c3ee21731ab4fec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_codeblocks-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for pytest_codeblocks-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8556d263e1204158c501f3638d306fa9ccfbd63950e8a73f5107f620023b126
MD5 88d8dd6adf6a30366c9671677f030272
BLAKE2b-256 a1be58300c6e01c1095128c0ad6f9a41bff42b08ff734d84291698490e990943

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