PyO3 / PyO3/pyo3

Add Python Doctests

Open
#5,795 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.2k
Forks
1k
Avg merge
2d 6h
Merged PRs (30d)
66

Description

In the current main branch we have 32 python code blocks in guide and 17 in src:

rg '```python' guide/ | wc -l
32
rg '```python' src/ | wc -l
17

As the project grows, it might become increasingly hard to check if those blocks are correct and up to date.

Adding python doctest or similar to nox and the CI can guarantee the scalability. With those checks, some categories of issues like https://github.com/PyO3/pyo3/issues/3639 would not exist.

Requirements

  • Have a way to skip tests (+SKIP, no_run)
  • Being able to run in .md, .py and .rs files
  • Hide any setup/teardown code in rendered documentation
  • Don't burden the CI 🤖

Some examples have two code blocks, one for the code and the other for the output. We may need to change them to adhere to doctest syntax or write our own plugin to check their validity.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the Python blocks in guide/ and src/ and the existing nox and CI configuration. Determine how doctest or a custom plugin can handle .md, .py, and .rs files, skips, separate output blocks, and hidden setup or teardown code. Done means the documented requirements are supported without an excessive CI burden.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
ci-cd, documentation, testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.