Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87f9b46

Browse files
committed
#15872: Some more Windows related tuning to shutil.rmtree tests
Turns out, the snakebite bots behave also their peculiarities. I'm really not proud of this stream of commits. :(
1 parent b9e9f3e commit 87f9b46

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

Lib/test/test_shutil.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,12 @@ def test_rmtree_errors(self):
132132
filename = os.path.join(tmpdir, "tstfile")
133133
with self.assertRaises(OSError) as cm:
134134
shutil.rmtree(filename)
135-
if cm.exception.filename.endswith('*.*'):
136-
rm_name = os.path.join(filename, '*.*')
137-
else:
138-
rm_name = filename
139-
self.assertEqual(cm.exception.filename, rm_name)
135+
# The reason for this rather odd construct is that Windows sprinkles
136+
# a \*.* at the end of file names. But only sometimes on some buildbots
137+
possible_args = [filename, os.path.join(filename, '*.*')]
138+
self.assertIn(cm.exception.filename, possible_args)
140139
self.assertTrue(os.path.exists(filename))
141-
# test that ignore_errors option is honoured
140+
# test that ignore_errors option is honored
142141
shutil.rmtree(filename, ignore_errors=True)
143142
self.assertTrue(os.path.exists(filename))
144143
errors = []
@@ -149,11 +148,11 @@ def onerror(*args):
149148
self.assertIs(errors[0][0], os.listdir)
150149
self.assertEqual(errors[0][1], filename)
151150
self.assertIsInstance(errors[0][2][1], OSError)
152-
self.assertEqual(errors[0][2][1].filename, rm_name)
151+
self.assertIn(errors[0][2][1].filename, possible_args)
153152
self.assertIs(errors[1][0], os.rmdir)
154153
self.assertEqual(errors[1][1], filename)
155154
self.assertIsInstance(errors[1][2][1], OSError)
156-
self.assertEqual(errors[1][2][1].filename, rm_name)
155+
self.assertIn(errors[1][2][1].filename, possible_args)
157156

158157
# See bug #1071513 for why we don't run this on cygwin
159158
# and bug #1076467 for why we don't run this as root.

0 commit comments

Comments
 (0)