Skip to content

docs: guard cache usage in cache fixture example#14269

Closed
kartikdp wants to merge 2 commits intopytest-dev:mainfrom
kartikdp:bugfix/cache-doc-guard
Closed

docs: guard cache usage in cache fixture example#14269
kartikdp wants to merge 2 commits intopytest-dev:mainfrom
kartikdp:bugfix/cache-doc-guard

Conversation

@kartikdp
Copy link

@kartikdp kartikdp commented Mar 6, 2026

Summary

This fixes a docs bug in the cache example.

The example in doc/en/how-to/cache.rst accessed pytestconfig.cache
directly, which can raise AttributeError when the cacheprovider plugin is
disabled (for example, with -p no:cacheprovider).

The fixture example now:

  • gets cache safely with getattr(pytestconfig, "cache", None)
  • skips when cache is unavailable
  • uses the local cache variable for get/set

closes #14148

Impact

  • Prevents runtime failure from a copy-pasted docs example in valid pytest
    configurations.
  • Improves correctness of official docs with minimal, docs-only change.
  • No behavior change to pytest runtime code.

How tested

  • uv run --with tox tox -e docs
  • Docs build passed with warnings as errors.

Checklist

  • Include documentation when adding new features. (Docs updated for this
    behavior)
  • Include new tests or update existing tests when applicable. (Not
    applicable: docs-only fix)
  • Allow maintainers to push and squash when merging my commits.
  • Add text like closes #XYZW to PR description and/or commits.
  • If AI agents were used, they are credited in Co-authored-by commit
    trailers.
  • Create a new changelog file in changelog (not required for this small
    docs fix).
  • Add yourself to AUTHORS (not required for this small docs fix).

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Mar 6, 2026
@kartikdp
Copy link
Author

kartikdp commented Mar 6, 2026

All checks are green; ready for review.

@kartikdp
Copy link
Author

kartikdp commented Mar 6, 2026

Thanks for reviewing. I noticed this overlaps with #14254, which was opened earlier and is already in review, so I’m closing this one as a duplicate.

@kartikdp kartikdp closed this Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

documentation recommends accessing config.cache in an unsafe way

2 participants