[PATCH] tests: fs_helper: check path validity during cleanup
Francesco Valla
francesco at valla.it
Sun May 31 23:15:09 CEST 2026
If the filesystem creation attempted by the FsHelper class fails, the
invocation of the cleanup function will cause a TypeError exception,
because the path of the filesystem itself, fed to os.remove(), will be
None. This will lead to a test failure even in case a skip is instead
wanted.
Such an exception will lead to a backtrace like this:
test/py/tests/test_fs/conftest.py:269: in fs_obj_basic
fsh.mk_fs()
test/py/tests/fs_helper.py:70: in mk_fs
self.fs_img = mk_fs(self.config, self.fs_type, self.size_mb << 20,
test/py/tests/fs_helper.py:246: in mk_fs
check_call(f'mkfs.{fs_lnxtype} {mkfs_opt} {fs_img}', shell=True,
/usr/lib64/python3.14/subprocess.py:420: in check_call
raise CalledProcessError(retcode, cmd)
E subprocess.CalledProcessError: Command '<...>' returned non-zero exit status 1.
During handling of the above exception, another exception occurred:
test/py/tests/test_fs/conftest.py:272: in fs_obj_basic
pytest.skip('Setup failed for filesystem: ' + fs_type + '. {}'.format(err))
E Skipped: Setup failed for filesystem: ext4. Command '<...>' returned non-zero exit status 1.
During handling of the above exception, another exception occurred:
test/py/tests/test_fs/conftest.py:277: in fs_obj_basic
fsh.cleanup()
test/py/tests/fs_helper.py:91: in cleanup
os.remove(self.fs_img)
E TypeError: remove: path should be string, bytes or os.PathLike, not NoneType
Fix this by checking if the variable containing the filesystem path is
valid before attempting to call os.remove() on it.
Fixes: 3691b1e4ce074 ("test: Convert fs_helper to use a class")
Signed-off-by: Francesco Valla <francesco at valla.it>
---
test/py/tests/fs_helper.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/test/py/tests/fs_helper.py b/test/py/tests/fs_helper.py
index ee779474ce60..e3824b2c1fdb 100644
--- a/test/py/tests/fs_helper.py
+++ b/test/py/tests/fs_helper.py
@@ -87,7 +87,7 @@ class FsHelper:
"""Remove created image"""
if self.tmpdir:
self.tmpdir.cleanup()
- if self._do_cleanup:
+ if self._do_cleanup and self.fs_img:
os.remove(self.fs_img)
def __enter__(self):
---
base-commit: 30b77f6aa146c96b831cb4ece038130b655b6a41
change-id: 20260531-test_fs_helper_fix-a280cf133870
Best regards,
--
Francesco Valla <francesco at valla.it>
More information about the U-Boot
mailing list