pytest-markdown-docs is a pytest plugin that collects and executes Python code blocks found within Markdown files and Python docstrings as tests. It allows developers to ensure that documentation examples remain correct and up-to-date by integrating them into the standard pytest test suite. The library is currently at version 0.9.2 and follows an active, though not strictly fixed, release cadence.
pip install pytest-markdown-docsNo compatibility data collected yet for this library.
To use pytest-markdown-docs, install it and then simply invoke pytest with the `--markdown-docs` flag, pointing it to your Markdown files or Python modules containing docstrings. The plugin will discover and run code fences tagged as `python`, `python3`, or `py`.
Always run `pytest --markdown-docs` to enable markdown/docstring test collection.
Be aware of this limitation when debugging failures in such blocks. Focus on the code content rather than exact line numbers in these specific cases.
Ensure your assert statements are clear. For complex data structures, consider explicitly printing values before the assertion to aid debugging.
Upgrade `pytest-markdown-docs` to version 0.9.0 or newer to ensure compatibility with `pytest` versions 7.0.0 and above. The current version (0.9.2) explicitly requires `pytest>=7.0.0`.
Use the `notest` info string for examples or snippets that should not be executed as part of your test suite.
Ensure Markdown files are in pytest's discovery path, contain fenced code blocks with `python` or `py` language specifiers, and verify `pytest-markdown-docs` is installed and active. You might need to specify `markdown_docs_paths` in `pytest.ini` or mark docstrings with `@pytest.mark.markdown_docs`.
Review the Python code within the specific Markdown code block or docstring referenced in the traceback and correct the syntax errors.
Correct the command-line option to its proper form, for example, change `--md-dryrun` to `--md-dry-run`, or ensure other options like `--md-collect-only` or `--md-strict` are spelled correctly.
Ensure that all Markdown files and related text files are saved with UTF-8 encoding. You may need to convert the file's encoding using a text editor or a command-line tool.