Sybil is a Python library designed for automated testing of examples embedded within your code and documentation. It parses examples from various source formats (like reStructuredText, Markdown, and Python docstrings) and evaluates them as part of your standard test suite, integrating with popular test runners such as pytest and unittest. The library is actively maintained, with frequent releases, and is currently at version 10.0.1.
pip install sybilVerified import paths — ran on the pinned version, not inferred.
To integrate Sybil with pytest, create a `conftest.py` file in your documentation's root directory. This example configures Sybil to collect doctests and Python code blocks from `.rst` files, and demonstrates how to provide pytest fixtures to the document's namespace. Remember to disable pytest's native doctest plugin in `pytest.ini` or `pyproject.toml`.
Add `addopts = -p no:doctest` to your `pytest.ini`, `pyproject.toml`, or `setup.cfg` file under the `[pytest]` section.
Ensure your `pytest` invocation path allows it to discover the `conftest.py` and the documentation files specified by `pattern`. Sybil's pytest integration handles file discovery via `pytest_collect_file` hooks.
Refer to the Sybil documentation to select the correct `sybil.parsers` for your content. For example, use `sybil.parsers.myst` for MyST Markdown or `sysybil.parsers.codeblock.PythonCodeBlockParser` for Python code.
Verify the PyPI project page (pypi.org/project/sybil) and documentation to confirm you have the correct library. Use specific import statements like `from sybil import Sybil`.
Run `pip install sybil` in your project's virtual environment.
Carefully review the indicated code block in your documentation or source file for syntax errors, incorrect indentation, or discrepancies between expected and actual output.
Ensure your `conftest.py` includes `pytest_collect_file = sybil.integration.pytest.pytest_collect_file(...)` with the correct parsers and paths, and verify that `pytest` is run from a directory where it can discover this `conftest.py` and your example files.
Pass the actual parser objects (e.g., `sybil.parsers.doctest`, `sybil.parsers.restructuredtext`) directly to the `pytest_collect_file` function.