]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
tests: fs_helper: check path validity during cleanup
authorFrancesco Valla <francesco@valla.it>
Sun, 31 May 2026 21:15:09 +0000 (23:15 +0200)
committerTom Rini <trini@konsulko.com>
Tue, 2 Jun 2026 23:29:22 +0000 (17:29 -0600)
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@valla.it>
test/py/tests/fs_helper.py

index ee779474ce60eb2660eb5b830c6cd85049299ea0..e3824b2c1fdba27f2cd6174620615867207cc936 100644 (file)
@@ -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):