Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include reason in cache path warnings #11005

Merged
merged 1 commit into from May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/11005.improvement.rst
@@ -0,0 +1 @@
Added underlying exception to cache provider path creation and write warning messages.
14 changes: 10 additions & 4 deletions src/_pytest/cacheprovider.py
Expand Up @@ -179,16 +179,22 @@
else:
cache_dir_exists_already = self._cachedir.exists()
path.parent.mkdir(exist_ok=True, parents=True)
except OSError:
self.warn("could not create cache path {path}", path=path, _ispytest=True)
except OSError as exc:
self.warn(
f"could not create cache path {path}: {exc}",
_ispytest=True,
)
return
if not cache_dir_exists_already:
self._ensure_supporting_files()
data = json.dumps(value, ensure_ascii=False, indent=2)
try:
f = path.open("w", encoding="UTF-8")
except OSError:
self.warn("cache could not write path {path}", path=path, _ispytest=True)
except OSError as exc:
self.warn(

Check warning on line 194 in src/_pytest/cacheprovider.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/cacheprovider.py#L193-L194

Added lines #L193 - L194 were not covered by tests
f"cache could not write path {path}: {exc}",
_ispytest=True,
)
else:
with f:
f.write(data)
Expand Down
2 changes: 1 addition & 1 deletion testing/test_cacheprovider.py
Expand Up @@ -87,7 +87,7 @@ def test_cache_failure_warns(
"*= warnings summary =*",
"*/cacheprovider.py:*",
" */cacheprovider.py:*: PytestCacheWarning: could not create cache path "
f"{unwritable_cache_dir}/v/cache/nodeids",
f"{unwritable_cache_dir}/v/cache/nodeids: *",
' config.cache.set("cache/nodeids", sorted(self.cached_nodeids))',
"*1 failed, 3 warnings in*",
]
Expand Down