{"id":13771892,"url":"https://github.com/nschloe/pytest-codeblocks","last_synced_at":"2025-12-12T00:38:13.368Z","repository":{"id":38215911,"uuid":"92733098","full_name":"nschloe/pytest-codeblocks","owner":"nschloe","description":":page_facing_up: Test code blocks in your READMEs","archived":false,"fork":false,"pushed_at":"2024-11-13T23:11:57.000Z","size":370,"stargazers_count":99,"open_issues_count":7,"forks_count":17,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-03T14:08:58.836Z","etag":null,"topics":["markdown","pytest","python","testing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nschloe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"nschloe","ko-fi":"nschloe"}},"created_at":"2017-05-29T11:21:10.000Z","updated_at":"2025-03-27T02:51:13.000Z","dependencies_parsed_at":"2023-12-26T06:36:29.363Z","dependency_job_id":"8b287b41-3efc-491c-bf8c-fcdd41b8b14b","html_url":"https://github.com/nschloe/pytest-codeblocks","commit_stats":{"total_commits":284,"total_committers":5,"mean_commits":56.8,"dds":"0.052816901408450745","last_synced_commit":"d0ca7e22b8e4d0c2d8807a9cf9e1f8ca7ef20442"},"previous_names":["nschloe/exdown"],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nschloe%2Fpytest-codeblocks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nschloe%2Fpytest-codeblocks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nschloe%2Fpytest-codeblocks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nschloe%2Fpytest-codeblocks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nschloe","download_url":"https://codeload.github.com/nschloe/pytest-codeblocks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248544029,"owners_count":21121878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["markdown","pytest","python","testing"],"created_at":"2024-08-03T17:00:57.185Z","updated_at":"2025-12-12T00:38:13.319Z","avatar_url":"https://github.com/nschloe.png","language":"Python","readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/nschloe/pytest-codeblocks\"\u003e\u003cimg alt=\"pytest-codeblocks\" src=\"https://nschloe.github.io/pytest-codeblocks/logo.svg\" width=\"60%\"\u003e\u003c/a\u003e\n  \u003cp align=\"center\"\u003eTest code blocks in your READMEs.\u003c/p\u003e\n\u003c/p\u003e\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\u0026logo=github\u0026label=Stars\u0026logoColor=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\u003c!--[![PyPi downloads](https://img.shields.io/pypi/dm/pytest-codeblocks.svg?style=flat-square)](https://pypistats.org/packages/pytest-codeblocks)--\u003e\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\u003c!--pytest.mark.skip--\u003e\n\n```python\nfoo + bar  # not working\n```\n\ndolor sit amet.\n````\n\n```markdown\n\u003c!--pytest.mark.skipif(sys.version_info \u003c= (3, 7), reason=\"Need at least Python 3.8\")--\u003e\n```\n\nYou can skip code blocks on import errors with\n\n```markdown\n\u003c!--pytest-codeblocks:importorskip(sympy)--\u003e\n```\n\nSkip the entire file by putting\n\n```markdown\n\u003c!--pytest-codeblocks:skipfile--\u003e\n```\n\nin the first line.\n\nFor expected errors, use `pytest.mark.xfail`:\n\n````markdown\nThe following gives an error:\n\n\u003c!--pytest.mark.xfail--\u003e\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\u003c!--pytest-codeblocks:cont--\u003e\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\u003c!--\n```python\na = 1\n```\n--\u003e\n\ndolor sit amet\n\n\u003c!--pytest-codeblocks:cont--\u003e\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\u003c!--pytest-codeblocks:expected-output--\u003e\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","funding_links":["https://github.com/sponsors/nschloe","nschloe"],"categories":["Plugins","Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnschloe%2Fpytest-codeblocks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnschloe%2Fpytest-codeblocks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnschloe%2Fpytest-codeblocks/lists"}