Skip to content

Commit dc525f4

Browse files
authored
bpo-35458: Fix test_shutil.test_disk_usage() (GH-11111)
The following test fails if a different process creates or removes a file on the same disk partition between the two lines: usage = shutil.disk_usage(os.path.dirname(__file__)) self.assertEqual(usage, shutil.disk_usage(__file__)) Only test that disk_usage() succeed on a filename, but don't check the result. Add also tests on the fields type (must be int).
1 parent 8905fcc commit dc525f4

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Lib/test/test_shutil.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,13 +1363,17 @@ def _boo(filename, extract_dir, extra):
13631363
"disk_usage not available on this platform")
13641364
def test_disk_usage(self):
13651365
usage = shutil.disk_usage(os.path.dirname(__file__))
1366-
self.assertEqual(usage, shutil.disk_usage(__file__))
1366+
for attr in ('total', 'used', 'free'):
1367+
self.assertIsInstance(getattr(usage, attr), int)
13671368
self.assertGreater(usage.total, 0)
13681369
self.assertGreater(usage.used, 0)
13691370
self.assertGreaterEqual(usage.free, 0)
13701371
self.assertGreaterEqual(usage.total, usage.used)
13711372
self.assertGreater(usage.total, usage.free)
13721373

1374+
# bpo-32557: Check that disk_usage() also accepts a filename
1375+
shutil.disk_usage(__file__)
1376+
13731377
@unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
13741378
@unittest.skipUnless(hasattr(os, 'chown'), 'requires os.chown')
13751379
def test_chown(self):

0 commit comments

Comments
 (0)