From b353d523a86775663ca2eebcd4741f3f3a9b1fe4 Mon Sep 17 00:00:00 2001 From: Francesco Valla Date: Sun, 31 May 2026 23:15:09 +0200 Subject: [PATCH] tests: fs_helper: check path validity during cleanup 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 --- 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 ee779474ce6..e3824b2c1fd 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): -- 2.47.3