Skip to content

Run doctests via pytest and fix broken doctests.#4000

Open
chuckwondo wants to merge 3 commits into
zarr-developers:mainfrom
chuckwondo:pytest-doctests
Open

Run doctests via pytest and fix broken doctests.#4000
chuckwondo wants to merge 3 commits into
zarr-developers:mainfrom
chuckwondo:pytest-doctests

Conversation

@chuckwondo
Copy link
Copy Markdown
Contributor

@chuckwondo chuckwondo commented May 22, 2026

Runs doctest via pytest and fixes all broken doctests.

Fixes #3498

TODO:

  • [ ] Add unit tests and/or doctests in docstrings
  • [ ] Add docstrings and API docs for any new/modified user-facing classes and functions
  • [ ] New/modified features documented in docs/user-guide/*.md
  • Changes documented as a new file in changes/
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

@github-actions github-actions Bot added the needs release notes Automatically applied to PRs which haven't added release notes label May 22, 2026
@github-actions github-actions Bot removed the needs release notes Automatically applied to PRs which haven't added release notes label May 22, 2026
Comment thread src/zarr/core/array.py
>>> arr = zarr.create_array(store, shape=(100, 80), chunks=(30, 40))
>>> import zarr.storage
>>> store = zarr.storage.MemoryStore()
>>> arr = zarr.create_array(store, dtype="i1", shape=(100, 80), chunks=(30, 40))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for these kinds of examples, we can use the URL form of the memorystore:

arr = zarr.create_array("memory:///", dtype="i1", shape=(100, 80), chunks=(30, 40))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nice! I'll tweak.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or "memory:/"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of scope ofc but we should labor to comply with the URL rules defined here: https://en.wikipedia.org/wiki/File_URI_scheme, specifically as regards number of slashes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also pass an empty dict {} as the store, that's probably even shorter, but it means you can't refer to the store later

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, not at this spot, but elsewhere. Let me get more specifics for you.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that reveals that the docstring tests are running in a shared session, which we probably don't want

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I think I see what's happening. It succeeds on the first test it hits that uses "memory:///", but all subsequent tests that use "memory:///" produce that error. Seems like they all use the same instance. Caching?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wouldn't call it caching, they just use the same in-memory store. But I don't think separate docstring snippets should run in the same sessions -- they should be run in completely separate sessions. is that something we can control?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I don't think we get the isolation you expect. If using "memory:///" causes some global state creation, it will be seen across all tests. Only tests running in separate interpreters would be fully isolated.

If you really would prefer use of the string, I propose opening a separate issue, as I don't think it's worth blocking this PR, especially since these are all pre-existing doctests, adjusted in this PR only to resolve pre-existing problems with them.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.55%. Comparing base (c0e2afa) to head (098db89).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4000      +/-   ##
==========================================
+ Coverage   93.49%   93.55%   +0.05%     
==========================================
  Files          88       88              
  Lines       11873    11873              
==========================================
+ Hits        11101    11108       +7     
+ Misses        772      765       -7     
Files with missing lines Coverage Δ
src/zarr/abc/store.py 96.42% <ø> (ø)
src/zarr/api/synchronous.py 92.95% <ø> (ø)
src/zarr/codecs/numcodecs/_codecs.py 96.38% <ø> (ø)
src/zarr/core/array.py 97.88% <ø> (+0.09%) ⬆️
src/zarr/core/group.py 95.20% <100.00%> (+0.22%) ⬆️
src/zarr/storage/_local.py 97.24% <ø> (+1.83%) ⬆️
src/zarr/storage/_memory.py 96.74% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

missing doctests

2 participants