Skip to content

Use sybil for doctests - #125

Merged
hagenw merged 9 commits into
mainfrom
use-sybil
Apr 15, 2026
Merged

Use sybil for doctests#125
hagenw merged 9 commits into
mainfrom
use-sybil

Conversation

@hagenw

@hagenw hagenw commented Apr 15, 2026

Copy link
Copy Markdown
Member

Replace jupyter-sphinx with sybil to test the usage documentation.

@sourcery-ai

sourcery-ai Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Replaces jupyter-sphinx-based execution of usage docs with Sybil-driven doctests integrated into pytest, including custom doctest handling and a fake user package to keep audobject’s serialization and versioning behavior consistent in documentation examples.

Sequence diagram for Sybil-based doctest execution via pytest

sequenceDiagram
    participant Pytest as pytest
    participant Conftest as docs_conftest
    participant SybilObj as Sybil_instance
    participant SybilCol as Sybil_pytest_collect_file
    participant Doctest as doctest_DocTestRunner
    participant Linecache as linecache
    participant MyPkg as mypkg_module
    participant Audobject as audobject

    Pytest->>Conftest: import conftest
    Conftest->>Conftest: patch doctest.DocTestRunner.run = _run_with_linecache
    Conftest->>Conftest: create _MyPkgModule and register in sys.modules
    Conftest->>Conftest: patch audobject.core.utils.get_version = _patched_get_version
    Conftest->>SybilObj: create Sybil(parsers, patterns, fixtures, setup=imports)
    Conftest->>SybilCol: SybilObj.pytest()

    Pytest->>SybilCol: pytest_collect_file(usage.rst)
    SybilCol->>SybilObj: parse usage.rst with DocTestParser, PythonCodeBlockParser, SkipParser
    SybilObj->>SybilCol: return pytest items for each example

    loop for each example
        Pytest->>SybilCol: execute example item
        SybilCol->>Conftest: call imports(namespace)
        Conftest->>MyPkg: _mypkg.bind_namespace(namespace)
        Conftest->>SybilCol: namespace seeded with __name__=mypkg, __version__=1.0.0, audobject

        SybilCol->>Doctest: run example via DocTestRunner.run
        Doctest->>Doctest: _run_with_linecache(test)
        Doctest->>Linecache: store example.source under <doctest name[index]>
        Doctest-->>SybilCol: return doctest result

        SybilCol->>Audobject: execute example code using audobject
        Audobject->>MyPkg: access classes via attribute lookup
        Audobject->>Audobject: audobject.core.utils.get_version(mypkg)
        Audobject->>Conftest: _patched_get_version(module_name)
        Conftest->>MyPkg: read __version__ from bound namespace
        Conftest-->>Audobject: return version
    end
Loading

Updated class diagram for doctest integration helpers and fake mypkg module

classDiagram
    class _MyPkgModule {
        - dict _namespace
        + _MyPkgModule(name)
        + bind_namespace(namespace) void
        + __getattr__(name) Any
    }

    class audobject_core_utils {
        + get_version(module_name) str
    }

    class patched_get_version {
        + _patched_get_version(module_name) str
    }

    class doctest_DocTestRunner {
        + run(test, *args, **kwargs) Any
    }

    class patched_doctest_runner {
        + _run_with_linecache(self, test, *args, **kwargs) Any
    }

    class Sybil {
        + Sybil(parsers, patterns, fixtures, setup)
        + pytest() callable
    }

    class imports_function {
        + imports(namespace) void
    }

    class run_in_tmpdir_fixture {
        + run_in_tmpdir(tmpdir_factory) generator
    }

    audobject_core_utils <|.. patched_get_version : patched
    doctest_DocTestRunner <|.. patched_doctest_runner : patched

    _MyPkgModule <-- imports_function : bind_namespace(namespace)
    patched_get_version --> _MyPkgModule : reads _namespace and __version__
    imports_function --> _MyPkgModule : sets __name__, __version__ via namespace

    Sybil --> imports_function : setup=imports
    Sybil --> run_in_tmpdir_fixture : uses fixture by name

    class pytest_integration {
        + pytest_collect_file
    }

    pytest_integration --> Sybil : uses
Loading

File-Level Changes

Change Details Files
Switch test and docs toolchain from jupyter-sphinx/doctestplus to Sybil-based doctest collection via pytest.
  • Remove jupyter-sphinx, ipykernel, and pytest-doctestplus from dev dependencies and add sybil while tightening pytest requirement.
  • Disable the standard doctest plugin in pytest configuration to avoid conflicts with Sybil’s doctest handling.
  • Remove the jupyter_sphinx Sphinx extension from the documentation configuration.
pyproject.toml
docs/conf.py
Introduce Sybil-based pytest integration to execute doctests and code blocks in usage.rst under a controlled environment compatible with audobject’s expectations.
  • Add docs/conftest.py defining Sybil collection for usage.rst with DocTestParser, PythonCodeBlockParser, and SkipParser, plus a module-scoped fixture to run tests in a temporary directory.
  • Wrap doctest.DocTestRunner.run so that each doctest example is registered in linecache with a unique synthetic filename, allowing inspect.getsource to work for functions defined in doctests.
  • Implement a fake mypkg module and patch audobject.core.utils.get_version so doctest-defined classes and version behave like they did under a Jupyter kernel, and wire this into Sybil’s setup function to seed the doctest namespace.
docs/conftest.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

sourcery-ai[bot]

This comment was marked as resolved.

@hagenw hagenw changed the title Use sybil Use sybil for doctests Apr 15, 2026
@hagenw

hagenw commented Apr 15, 2026

Copy link
Copy Markdown
Member Author

@sourcery-ai review

sourcery-ai[bot]

This comment was marked as resolved.

@codecov

codecov Bot commented Apr 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (aa786c3) to head (97587cc).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
Files with missing lines Coverage Δ
audobject/core/conftest.py 100.0% <100.0%> (ø)
audobject/core/resolver.py 100.0% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hagenw
hagenw merged commit 719180b into main Apr 15, 2026
20 checks passed
@hagenw
hagenw deleted the use-sybil branch April 15, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant