This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: test_shutil.test_disk_usage() randomly fails when tests are run in parallel
Type: Stage: resolved
Components: Tests Versions: Python 3.8
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pablogsal, vstinner
Priority: normal Keywords: patch

Created on 2018-12-11 10:37 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11111 merged vstinner, 2018-12-11 10:41
Messages (4)
msg331601 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-12-11 10:37
Extract of the test:

        usage = shutil.disk_usage(os.path.dirname(__file__))
        self.assertEqual(usage, shutil.disk_usage(__file__))

The test fails if another process creates or removes data on the disk partition. IMHO "self.assertEqual(usage, shutil.disk_usage(__file__))" must be removed, it cannot be reliable without mocking os.statvfs() / nt._getdiskusage().

Even if tests are run sequentially, the test can fail if a program creates a file between the two lines of code, the test cannot be reliable.

FAIL: test_disk_usage (test.test_shutil.TestShutil)
Traceback (most recent call last):
  File "/home/shager/cpython-buildarea/3.x.edelsohn-fedora-ppc64le/build/Lib/test/", line 1366, in test_disk_usage
    self.assertEqual(usage, shutil.disk_usage(__file__))
AssertionError: usage(total=1925696024576, used=1793793806336, free=131902218240) != usage(total=1925696024576, used=1793793818624, free=131902205952)
msg331602 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-12-11 10:43
The new test has been added by PR 9372:

commit c8c0249c9e8f61ab7670119a5a5278354df27bbb
Author: Joe Pamer <>
Date:   Tue Sep 25 10:57:36 2018 -0400

    bpo-32557: allow shutil.disk_usage to take a file path on Windows also (GH-9372)
msg331606 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-12-11 10:57
Only the master branch is impacted (see bpo-32557).
msg331609 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-12-11 11:05
New changeset dc525f4315cdbe84693396d3f7a65a00425743bb by Victor Stinner in branch 'master':
bpo-35458: Fix test_shutil.test_disk_usage() (GH-11111)
Date User Action Args
2022-04-11 14:59:09adminsetgithub: 79639
2018-12-11 11:05:35vstinnersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-12-11 11:05:25vstinnersetmessages: + msg331609
2018-12-11 10:57:55vstinnersetmessages: + msg331606
2018-12-11 10:43:46vstinnersetmessages: + msg331602
2018-12-11 10:41:37vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request10340
2018-12-11 10:37:38vstinnercreate