From: Giampaolo Rodola Date: Wed, 5 Feb 2020 17:20:52 +0000 (+0100) Subject: bpo-39488: Skip test_largefile tests if not enough disk space (GH-18261) X-Git-Tag: v3.9.0a4~127 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b39fb8e847ac59b539ad7e93df91c1709815180e;p=thirdparty%2FPython%2Fcpython.git bpo-39488: Skip test_largefile tests if not enough disk space (GH-18261) --- diff --git a/Lib/test/test_largefile.py b/Lib/test/test_largefile.py index e309282d73e2..c254b047e1ec 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: