https://github.com/python/cpython/commit/68ebc051fc8285a06352195c22abdc1e1c7ec37c
commit: 68ebc051fc8285a06352195c22abdc1e1c7ec37c
branch: main
author: Gregory P. Smith <[email protected]>
committer: gpshead <[email protected]>
date: 2026-05-19T01:19:06Z
summary:

gh-86533: Make Path.mkdir parent_mode tests umask-independent (#150040)

test_mkdir_with_parent_mode, test_mkdir_parent_mode_deep_hierarchy and
test_mkdir_parent_mode_same_as_mode assert exact directory mode bits but
did not pin the process umask.  On buildbots running with a restrictive
umask (e.g. 0o077) the 0o755 leaf was masked down to 0o700, failing the
assertions.  Wrap them in os_helper.temp_umask(0o022), matching the
other umask-aware mkdir tests in this file.

files:
M Lib/test/test_pathlib/test_pathlib.py

diff --git a/Lib/test/test_pathlib/test_pathlib.py 
b/Lib/test/test_pathlib/test_pathlib.py
index 5d13d5aadc7412..2cb4876f5c6400 100644
--- a/Lib/test/test_pathlib/test_pathlib.py
+++ b/Lib/test/test_pathlib/test_pathlib.py
@@ -2526,14 +2526,15 @@ def test_mkdir_with_parent_mode(self):
         p = self.cls(self.base, 'newdirPM', 'subdirPM')
         self.assertFalse(p.exists())
         if os.name != 'nt':
-            # Specify different modes for parent and leaf directories
-            p.mkdir(0o755, parents=True, parent_mode=0o750)
-            self.assertTrue(p.exists())
-            self.assertTrue(p.is_dir())
-            # Leaf directory gets the mode parameter
-            self.assertEqual(p.stat().st_mode & 0o777, 0o755)
-            # Parent directory gets the parent_mode parameter
-            self.assertEqual(p.parent.stat().st_mode & 0o777, 0o750)
+            with os_helper.temp_umask(0o022):
+                # Specify different modes for parent and leaf directories
+                p.mkdir(0o755, parents=True, parent_mode=0o750)
+                self.assertTrue(p.exists())
+                self.assertTrue(p.is_dir())
+                # Leaf directory gets the mode parameter
+                self.assertEqual(p.stat().st_mode & 0o777, 0o755)
+                # Parent directory gets the parent_mode parameter
+                self.assertEqual(p.parent.stat().st_mode & 0o777, 0o750)
 
     @unittest.skipIf(
         is_emscripten or is_wasi,
@@ -2548,15 +2549,16 @@ def test_mkdir_parent_mode_deep_hierarchy(self):
         p = self.cls(self.base, 'level1PM', 'level2PM', 'level3PM')
         self.assertFalse(p.exists())
         if os.name != 'nt':
-            p.mkdir(0o755, parents=True, parent_mode=0o700)
-            self.assertTrue(p.exists())
-            # Check that all parent directories have parent_mode
-            level1 = self.cls(self.base, 'level1PM')
-            level2 = level1 / 'level2PM'
-            self.assertEqual(level1.stat().st_mode & 0o777, 0o700)
-            self.assertEqual(level2.stat().st_mode & 0o777, 0o700)
-            # Leaf directory has the regular mode
-            self.assertEqual(p.stat().st_mode & 0o777, 0o755)
+            with os_helper.temp_umask(0o022):
+                p.mkdir(0o755, parents=True, parent_mode=0o700)
+                self.assertTrue(p.exists())
+                # Check that all parent directories have parent_mode
+                level1 = self.cls(self.base, 'level1PM')
+                level2 = level1 / 'level2PM'
+                self.assertEqual(level1.stat().st_mode & 0o777, 0o700)
+                self.assertEqual(level2.stat().st_mode & 0o777, 0o700)
+                # Leaf directory has the regular mode
+                self.assertEqual(p.stat().st_mode & 0o777, 0o755)
 
     @unittest.skipIf(
         is_emscripten or is_wasi,
@@ -2593,11 +2595,12 @@ def test_mkdir_parent_mode_same_as_mode(self):
         p = self.cls(self.base, 'samedirPM', 'subdirPM')
         self.assertFalse(p.exists())
         if os.name != 'nt':
-            p.mkdir(0o705, parents=True, parent_mode=0o705)
-            self.assertTrue(p.exists())
-            # Both directories should have the same mode
-            self.assertEqual(p.stat().st_mode & 0o777, 0o705)
-            self.assertEqual(p.parent.stat().st_mode & 0o777, 0o705)
+            with os_helper.temp_umask(0o022):
+                p.mkdir(0o705, parents=True, parent_mode=0o705)
+                self.assertTrue(p.exists())
+                # Both directories should have the same mode
+                self.assertEqual(p.stat().st_mode & 0o777, 0o705)
+                self.assertEqual(p.parent.stat().st_mode & 0o777, 0o705)
 
     @needs_symlinks
     def test_symlink_to(self):

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to