From b39fb8e847ac59b539ad7e93df91c1709815180e Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola Date: Wed, 5 Feb 2020 18:20:52 +0100 Subject: [PATCH] bpo-39488: Skip test_largefile tests if not enough disk space (GH-18261) --- Lib/test/test_largefile.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Lib/test/test_largefile.py b/Lib/test/test_largefile.py index e309282d73e..c254b047e1e 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: