pytest_codeblocks


Namepytest_codeblocks JSON
Version 0.17.0 PyPI version JSON
download
home_pageNone
SummaryTest code blocks in your READMEs
upload_time2023-09-17 19:17:31
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <a href="https://github.com/nschloe/pytest-codeblocks"><img alt="pytest-codeblocks" src="https://nschloe.github.io/pytest-codeblocks/logo.svg" width="60%"></a>
  <p align="center">Test code blocks in your READMEs.</p>
</p>

[![PyPi Version](https://img.shields.io/pypi/v/pytest-codeblocks.svg?style=flat-square)](https://pypi.org/project/pytest_codeblocks/)
[![Anaconda Cloud](https://anaconda.org/conda-forge/pytest-codeblocks/badges/version.svg?=style=flat-square)](https://anaconda.org/conda-forge/pytest-codeblocks/)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/pytest-codeblocks.svg?style=flat-square)](https://pypi.org/project/pytest_codeblocks/)
[![GitHub stars](https://img.shields.io/github/stars/nschloe/pytest-codeblocks.svg?style=flat-square&logo=github&label=Stars&logoColor=white)](https://github.com/nschloe/pytest-codeblocks)
[![Downloads](https://static.pepy.tech/badge/pytest-codeblocks/month?style=flat-square)](https://www.pepy.tech/projects/pytest-codeblocks)

<!--[![PyPi downloads](https://img.shields.io/pypi/dm/pytest-codeblocks.svg?style=flat-square)](https://pypistats.org/packages/pytest-codeblocks)-->

[![gh-actions](https://img.shields.io/github/actions/workflow/status/nschloe/pytest-codeblocks/tests?style=flat-square)](https://github.com/nschloe/pytest-codeblocks/actions?query=workflow%3Atests)
[![codecov](https://img.shields.io/codecov/c/github/nschloe/pytest-codeblocks.svg?style=flat-square)](https://app.codecov.io/gh/nschloe/pytest-codeblocks)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square)](https://github.com/psf/black)

This is pytest-codeblocks, a [pytest](https://pytest.org/) plugin for testing code
blocks from README files. It supports Python and shell code.

Install with

```sh
pip install pytest-codeblocks
```

and run pytest with

```sh
pytest --codeblocks
```

```sh
================================= 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.

#### Marking code blocks

It is possible to use `pytest.mark` for marking code blocks. For example,
to skip a code block use `pytest.mark.skip` or `pytest.mark.skipif`:

````markdown
Lorem ipsum

<!--pytest.mark.skip-->

```python
foo + bar  # not working
```

dolor sit amet.
````

```markdown
<!--pytest.mark.skipif(sys.version_info <= (3, 7), reason="Need at least Python 3.8")-->
```

You can skip code blocks on import errors with

```markdown
<!--pytest-codeblocks:importorskip(sympy)-->
```

Skip the entire file by putting

```markdown
<!--pytest-codeblocks:skipfile-->
```

in the first line.

For expected errors, use `pytest.mark.xfail`:

````markdown
The following gives an error:

<!--pytest.mark.xfail-->

```python
1 / 0
```
````

#### Merging code blocks

Broken-up code blocks can be merged into one with the `pytest-codeblocks:cont` prefix

````markdown
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:

````markdown
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:

````markdown
This

```sh
print(1 + 3)
```

gives

<!--pytest-codeblocks:expected-output-->

```
4
```
````

Use `expected-output-ignore-whitespace` if you'd like whitespace differences to
be ignored.

(Conditionally) Skipping the output verfication works by prepending the first
block with `skip`/`skipif` (see [above](#skipping-code-blocks)).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pytest_codeblocks",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "Nico Schl\u00f6mer <nico.schloemer@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/a5/99/1ee3017a525dcb36566f0523938fbc20fb33ef8bf957205fafe6659f3a60/pytest_codeblocks-0.17.0.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <a href=\"https://github.com/nschloe/pytest-codeblocks\"><img alt=\"pytest-codeblocks\" src=\"https://nschloe.github.io/pytest-codeblocks/logo.svg\" width=\"60%\"></a>\n  <p align=\"center\">Test code blocks in your READMEs.</p>\n</p>\n\n[![PyPi Version](https://img.shields.io/pypi/v/pytest-codeblocks.svg?style=flat-square)](https://pypi.org/project/pytest_codeblocks/)\n[![Anaconda Cloud](https://anaconda.org/conda-forge/pytest-codeblocks/badges/version.svg?=style=flat-square)](https://anaconda.org/conda-forge/pytest-codeblocks/)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/pytest-codeblocks.svg?style=flat-square)](https://pypi.org/project/pytest_codeblocks/)\n[![GitHub stars](https://img.shields.io/github/stars/nschloe/pytest-codeblocks.svg?style=flat-square&logo=github&label=Stars&logoColor=white)](https://github.com/nschloe/pytest-codeblocks)\n[![Downloads](https://static.pepy.tech/badge/pytest-codeblocks/month?style=flat-square)](https://www.pepy.tech/projects/pytest-codeblocks)\n\n<!--[![PyPi downloads](https://img.shields.io/pypi/dm/pytest-codeblocks.svg?style=flat-square)](https://pypistats.org/packages/pytest-codeblocks)-->\n\n[![gh-actions](https://img.shields.io/github/actions/workflow/status/nschloe/pytest-codeblocks/tests?style=flat-square)](https://github.com/nschloe/pytest-codeblocks/actions?query=workflow%3Atests)\n[![codecov](https://img.shields.io/codecov/c/github/nschloe/pytest-codeblocks.svg?style=flat-square)](https://app.codecov.io/gh/nschloe/pytest-codeblocks)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square)](https://github.com/psf/black)\n\nThis is pytest-codeblocks, a [pytest](https://pytest.org/) plugin for testing code\nblocks from README files. It supports Python and shell code.\n\nInstall with\n\n```sh\npip install pytest-codeblocks\n```\n\nand run pytest with\n\n```sh\npytest --codeblocks\n```\n\n```sh\n================================= test session starts =================================\nplatform linux -- Python 3.9.4, pytest-6.2.4, py-1.10.0, pluggy-0.13.1\nrootdir: /path/to/directory\nplugins: codeblocks-0.11.0\ncollected 56 items\n\nexample.md .......................                                              [ 50%]\nREADME.md .......................                                               [100%]\n\n================================= 56 passed in 0.08s ==================================\n```\n\npytest-codeblocks will only pick up code blocks with `python` and `sh`/`bash`/`zsh`\nsyntax highlighting.\n\n#### Marking code blocks\n\nIt is possible to use `pytest.mark` for marking code blocks. For example,\nto skip a code block use `pytest.mark.skip` or `pytest.mark.skipif`:\n\n````markdown\nLorem ipsum\n\n<!--pytest.mark.skip-->\n\n```python\nfoo + bar  # not working\n```\n\ndolor sit amet.\n````\n\n```markdown\n<!--pytest.mark.skipif(sys.version_info <= (3, 7), reason=\"Need at least Python 3.8\")-->\n```\n\nYou can skip code blocks on import errors with\n\n```markdown\n<!--pytest-codeblocks:importorskip(sympy)-->\n```\n\nSkip the entire file by putting\n\n```markdown\n<!--pytest-codeblocks:skipfile-->\n```\n\nin the first line.\n\nFor expected errors, use `pytest.mark.xfail`:\n\n````markdown\nThe following gives an error:\n\n<!--pytest.mark.xfail-->\n\n```python\n1 / 0\n```\n````\n\n#### Merging code blocks\n\nBroken-up code blocks can be merged into one with the `pytest-codeblocks:cont` prefix\n\n````markdown\nLorem ipsum\n\n```python\na = 1\n```\n\ndolor sit amet\n\n<!--pytest-codeblocks:cont-->\n\n```python\n# this would otherwise fail since `a` is not defined\na + 1\n```\n````\n\nIf you'd like to prepend code that you don't want to show, you can just comment it out;\npytest-codeblocks will pick it up anyway:\n\n````markdown\nLorem ipsum\n\n<!--\n```python\na = 1\n```\n-->\n\ndolor sit amet\n\n<!--pytest-codeblocks:cont-->\n\n```python\n# this would otherwise fail since `a` is not defined\na + 1\n```\n````\n\n#### Expected output\n\nYou can also define the expected output of a code block:\n\n````markdown\nThis\n\n```sh\nprint(1 + 3)\n```\n\ngives\n\n<!--pytest-codeblocks:expected-output-->\n\n```\n4\n```\n````\n\nUse `expected-output-ignore-whitespace` if you'd like whitespace differences to\nbe ignored.\n\n(Conditionally) Skipping the output verfication works by prepending the first\nblock with `skip`/`skipif` (see [above](#skipping-code-blocks)).\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Test code blocks in your READMEs",
    "version": "0.17.0",
    "project_urls": {
        "Code": "https://github.com/nschloe/pytest-codeblocks",
        "Funding": "https://github.com/sponsors/nschloe",
        "Homepage": "https://github.com/nschloe/pytest-codeblocks",
        "Issues": "https://github.com/nschloe/pytest-codeblocks/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "fa2c503f797c7ac1e35d81944f8fbcf3ea7a1965e435676570a833035d8d0937",
                "md5": "a5a5daf60f3a540eea2c598a4a6bd271",
                "sha256": "b2aed8e66c3ce65435630783b391e7c7ae46f80b8220d3fa1bb7c689b36e78ad"
            },
            "downloads": -1,
            "filename": "pytest_codeblocks-0.17.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a5a5daf60f3a540eea2c598a4a6bd271",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7716,
            "upload_time": "2023-09-17T19:17:29",
            "upload_time_iso_8601": "2023-09-17T19:17:29.506561Z",
            "url": "https://files.pythonhosted.org/packages/fa/2c/503f797c7ac1e35d81944f8fbcf3ea7a1965e435676570a833035d8d0937/pytest_codeblocks-0.17.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a5991ee3017a525dcb36566f0523938fbc20fb33ef8bf957205fafe6659f3a60",
                "md5": "541476d994c58528ea1116e907539a9b",
                "sha256": "446e1babd182f54b4f113d567737a22f5405cade144c08a0085b2985247943d5"
            },
            "downloads": -1,
            "filename": "pytest_codeblocks-0.17.0.tar.gz",
            "has_sig": false,
            "md5_digest": "541476d994c58528ea1116e907539a9b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 11176,
            "upload_time": "2023-09-17T19:17:31",
            "upload_time_iso_8601": "2023-09-17T19:17:31.050328Z",
            "url": "https://files.pythonhosted.org/packages/a5/99/1ee3017a525dcb36566f0523938fbc20fb33ef8bf957205fafe6659f3a60/pytest_codeblocks-0.17.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-17 19:17:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nschloe",
    "github_project": "pytest-codeblocks",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pytest_codeblocks"
}
        
Elapsed time: 0.15949s