cpython: 1134198e23bd (original) (raw)

--- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -166,6 +166,13 @@ def _get_default_tempdir(): return dir except FileExistsError: pass

@@ -296,6 +304,14 @@ def mkdtemp(suffix="", prefix=template, return file except FileExistsError: continue # try again

raise FileExistsError(_errno.EEXIST, "No usable temporary directory name found")

--- a/Lib/test/test_tempfile.py +++ b/Lib/test/test_tempfile.py @@ -275,7 +275,39 @@ def _mock_candidate_names(*names): lambda: iter(names)) -class TestMkstempInner(BaseTestCase): +class TestBadTempdir: +

+

+

+ + +class TestMkstempInner(TestBadTempdir, BaseTestCase): """Test the internal function _mkstemp_inner.""" class mkstemped: @@ -390,7 +422,7 @@ class TestMkstempInner(BaseTestCase): os.lseek(f.fd, 0, os.SEEK_SET) self.assertEqual(os.read(f.fd, 20), b"blat")

@@ -401,11 +433,11 @@ class TestMkstempInner(BaseTestCase): # the chosen name already exists with _inside_empty_temp_dir(), [](#l2.55) _mock_candidate_names('aaa', 'aaa', 'bbb'):

@@ -417,7 +449,7 @@ class TestMkstempInner(BaseTestCase): dir = tempfile.mkdtemp() self.assertTrue(dir.endswith('aaa'))

@@ -529,9 +561,12 @@ class TestMkstemp(BaseTestCase): os.rmdir(dir) -class TestMkdtemp(BaseTestCase): +class TestMkdtemp(TestBadTempdir, BaseTestCase): """Test mkdtemp()."""

+ def do_create(self, dir=None, pre="", suf=""): if dir is None: dir = tempfile.gettempdir()

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -52,6 +52,11 @@ Core and Builtins Library ------- +- Issue #22107: tempfile.gettempdir() and tempfile.mkdtemp() now try again