diff options
author | Ran Benita <ran@unusedvar.com> | 2024-05-15 10:57:10 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-15 10:57:10 +0300 |
commit | fa1d5be3e8b0a34106b35eff092adaa67c9de503 (patch) | |
tree | 00448dd45f29d2dd7850c57b1661b386c989d336 | |
parent | ae1a47e050fcf9715dd01e6b31412d9223662b60 (diff) | |
parent | 3a64c47f1f713fbc154d04960fe8382ecf94bdc4 (diff) | |
download | pytest-upstream-main.tar.gz |
Merge pull request #12325 from bluetech/pytest-cache-755upstream-main
cacheprovider: fix `.pytest_cache` not being world-readable
-rw-r--r-- | changelog/12308.bugfix.rst | 1 | ||||
-rwxr-xr-x | src/_pytest/cacheprovider.py | 7 | ||||
-rw-r--r-- | testing/test_cacheprovider.py | 15 |
3 files changed, 23 insertions, 0 deletions
diff --git a/changelog/12308.bugfix.rst b/changelog/12308.bugfix.rst new file mode 100644 index 000000000..07995427a --- /dev/null +++ b/changelog/12308.bugfix.rst @@ -0,0 +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``. diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py index 4593e2a81..06def557e 100755 --- a/src/_pytest/cacheprovider.py +++ b/src/_pytest/cacheprovider.py @@ -213,6 +213,13 @@ class Cache: dir=self._cachedir.parent, ) as newpath: path = Path(newpath) + + # Reset permissions to the default, see #12308. + # Note: there's no way to get the current umask atomically, eek. + umask = os.umask(0o022) + os.umask(umask) + path.chmod(0o777 - umask) + with open(path.joinpath("README.md"), "xt", encoding="UTF-8") as f: f.write(README_CONTENT) with open(path.joinpath(".gitignore"), "xt", encoding="UTF-8") as f: diff --git a/testing/test_cacheprovider.py b/testing/test_cacheprovider.py index 6c18c358a..c85c1d04c 100644 --- a/testing/test_cacheprovider.py +++ b/testing/test_cacheprovider.py @@ -31,6 +31,21 @@ class TestNewAPI: p = config.cache.mkdir("name") assert p.is_dir() + def test_cache_dir_permissions(self, pytester: Pytester) -> None: + """The .pytest_cache directory should have world-readable permissions + (depending on umask). + + Regression test for #12308. + """ + pytester.makeini("[pytest]") + config = pytester.parseconfigure() + assert config.cache is not None + p = config.cache.mkdir("name") + assert p.is_dir() + # Instead of messing with umask, make sure .pytest_cache has the same + # permissions as the default that `mkdir` gives `p`. + assert (p.parent.stat().st_mode & 0o777) == (p.stat().st_mode & 0o777) + def test_config_cache_dataerror(self, pytester: Pytester) -> None: pytester.makeini("[pytest]") config = pytester.parseconfigure() |