Skip to content

Commit f179bf2

Browse files
authored
Merge pull request #12327 from pytest-dev/backport-12325-to-8.2.x
[8.2.x] cacheprovider: fix `.pytest_cache` not being world-readable
2 parents 65ab7cb + 2b671b5 commit f179bf2

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

changelog/12308.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a regression in pytest 8.2.0 where the permissions of automatically-created ``.pytest_cache`` directories became ``rwx------`` instead of the expected ``rwxr-xr-x``.

src/_pytest/cacheprovider.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ def _ensure_cache_dir_and_supporting_files(self) -> None:
213213
dir=self._cachedir.parent,
214214
) as newpath:
215215
path = Path(newpath)
216+
217+
# Reset permissions to the default, see #12308.
218+
# Note: there's no way to get the current umask atomically, eek.
219+
umask = os.umask(0o022)
220+
os.umask(umask)
221+
path.chmod(0o777 - umask)
222+
216223
with open(path.joinpath("README.md"), "xt", encoding="UTF-8") as f:
217224
f.write(README_CONTENT)
218225
with open(path.joinpath(".gitignore"), "xt", encoding="UTF-8") as f:

testing/test_cacheprovider.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ def test_config_cache_mkdir(self, pytester: Pytester) -> None:
3131
p = config.cache.mkdir("name")
3232
assert p.is_dir()
3333

34+
def test_cache_dir_permissions(self, pytester: Pytester) -> None:
35+
"""The .pytest_cache directory should have world-readable permissions
36+
(depending on umask).
37+
38+
Regression test for #12308.
39+
"""
40+
pytester.makeini("[pytest]")
41+
config = pytester.parseconfigure()
42+
assert config.cache is not None
43+
p = config.cache.mkdir("name")
44+
assert p.is_dir()
45+
# Instead of messing with umask, make sure .pytest_cache has the same
46+
# permissions as the default that `mkdir` gives `p`.
47+
assert (p.parent.stat().st_mode & 0o777) == (p.stat().st_mode & 0o777)
48+
3449
def test_config_cache_dataerror(self, pytester: Pytester) -> None:
3550
pytester.makeini("[pytest]")
3651
config = pytester.parseconfigure()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy