Warn when writing or closing a cache file fails - #15044
Conversation
Co-authored-by: Codex <noreply@openai.com>
| data = json.dumps(value, ensure_ascii=False, indent=2) | ||
| try: | ||
| f = path.open("w", encoding="UTF-8") | ||
| with path.open("w", encoding="UTF-8") as f: |
There was a problem hiding this comment.
Nitpick we now can use path.write_text
There was a problem hiding this comment.
ah yes! switched to path.write_text
Co-authored-by: Codex <noreply@openai.com>
Warn when writing or closing a cache file fails (pytest-dev#15044)
|
Nice consolidation — collapsing the open/write/close paths into a single Two observations from reading the final state of Second, on the test itself: it patches |
Fixes #15043.
cache.set()already warns when opening a cache file fails, but anOSErrorfrom writing or closing it currently escapes. Move the existing write into the same error handler so these failures also producePytestCacheWarning.The regression test covers open, write, and close failures. The write and close cases fail before the fix; all three pass afterward. A separate reproduction using a real file-size limit also fails on pytest 9.1.1 and unmodified main, then produces warnings with this fix.
Checks on macOS:
tox -e py313 -- -q: 4,607 passed, 51 skipped, 15 xfailed, 5 xpassed.tox -e linting: passed.JSON serialization and warning filters keep their existing behavior.
Co-developed by Poorva Barve and Codex.