From fabfe760fb0324c6e2b45968e73425818419ac88 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Thu, 25 Sep 2025 12:29:18 +0200 Subject: [PATCH] Fix flaky test_get_dir_structure_sizes_ebadmsg_error (#6211) --- tests/hardware/test_disk.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/hardware/test_disk.py b/tests/hardware/test_disk.py index 5ed0d9f25..2e435b149 100644 --- a/tests/hardware/test_disk.py +++ b/tests/hardware/test_disk.py @@ -326,7 +326,8 @@ def test_get_dir_structure_sizes_ebadmsg_error(coresys, tmp_path): return os.path.islink(self) def mock_stat_ebadmsg(self, follow_symlinks=True): - if self == subdir: + # Raise EBADMSG for any child of test_dir to ensure consistent behavior + if self.parent == test_dir: raise OSError(errno.EBADMSG, "Bad message") # For other paths, use the real os.stat return os.stat(self, follow_symlinks=follow_symlinks) @@ -338,8 +339,8 @@ def test_get_dir_structure_sizes_ebadmsg_error(coresys, tmp_path): ): result = coresys.hardware.disk.get_dir_structure_sizes(test_dir) - # The EBADMSG error should cause the loop to break, so we get 0 used space - # because the error happens before processing the file in the root directory + # The EBADMSG error should cause the loop to break on the first child + # Since all children raise EBADMSG, we should get 0 used space assert result["used_bytes"] == 0 assert "children" not in result