diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2020-02-05 17:20:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-05 17:20:52 (GMT) |
commit | b39fb8e847ac59b539ad7e93df91c1709815180e (patch) | |
tree | 77ae0c8666f0f11b53d73b6aa4fd9b3a49adfa41 /Lib/test/test_largefile.py | |
parent | bf305cc6f05948f264349a6a6c6fd7d49c1839d3 (diff) | |
download | cpython-b39fb8e847ac59b539ad7e93df91c1709815180e.zip cpython-b39fb8e847ac59b539ad7e93df91c1709815180e.tar.gz cpython-b39fb8e847ac59b539ad7e93df91c1709815180e.tar.bz2 |
bpo-39488: Skip test_largefile tests if not enough disk space (GH-18261)
Diffstat (limited to 'Lib/test/test_largefile.py')
-rw-r--r-- | Lib/test/test_largefile.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_largefile.py b/Lib/test/test_largefile.py index e309282..c254b04 100644 --- a/Lib/test/test_largefile.py +++ b/Lib/test/test_largefile.py @@ -151,9 +151,24 @@ class TestFileMethods(LargeFileTest): self.assertTrue(f.seekable()) +def skip_no_disk_space(path, required): + def decorator(fun): + def wrapper(*args, **kwargs): + if shutil.disk_usage(os.path.realpath(path)).free < required: + hsize = int(required / 1024 / 1024) + raise unittest.SkipTest( + f"required {hsize} MiB of free disk space") + return fun(*args, **kwargs) + return wrapper + return decorator + + class TestCopyfile(LargeFileTest, unittest.TestCase): open = staticmethod(io.open) + # Exact required disk space would be (size * 2), but let's give it a + # bit more tolerance. + @skip_no_disk_space(TESTFN, size * 2.5) def test_it(self): # Internally shutil.copyfile() can use "fast copy" methods like # os.sendfile(). @@ -200,6 +215,9 @@ class TestSocketSendfile(LargeFileTest, unittest.TestCase): self.thread.start() event.set() + # Exact required disk space would be (size * 2), but let's give it a + # bit more tolerance. + @skip_no_disk_space(TESTFN, size * 2.5) def test_it(self): port = find_unused_port() with socket.create_server(("", port)) as sock: |