[PATCH] tests: Fix exception when cleaning up skipped test

Joshua Watt jpewhacker at gmail.com
Mon Jul 3 15:35:09 CEST 2023


If test_cat and test_xxd cannot create the required file, the test will
be skipped, but this would result in an exception being raised in the
finally block because the file didn't exist to be cleaned up. This
caused the test to be marked as failed instead of skipped.

Signed-off-by: Joshua Watt <JPEWhacker at gmail.com>
---
 test/py/tests/test_cat/conftest.py | 3 ++-
 test/py/tests/test_xxd/conftest.py | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/test/py/tests/test_cat/conftest.py b/test/py/tests/test_cat/conftest.py
index 058fe52352..ef1c54d513 100644
--- a/test/py/tests/test_cat/conftest.py
+++ b/test/py/tests/test_cat/conftest.py
@@ -32,4 +32,5 @@ def cat_data(u_boot_config):
         pytest.skip('Setup failed')
     finally:
         shutil.rmtree(mnt_point)
-        os.remove(image_path)
+        if os.path.exists(image_path):
+            os.remove(image_path)
diff --git a/test/py/tests/test_xxd/conftest.py b/test/py/tests/test_xxd/conftest.py
index 59285aadf4..481a794961 100644
--- a/test/py/tests/test_xxd/conftest.py
+++ b/test/py/tests/test_xxd/conftest.py
@@ -32,4 +32,5 @@ def xxd_data(u_boot_config):
         pytest.skip('Setup failed')
     finally:
         shutil.rmtree(mnt_point)
-        os.remove(image_path)
+        if os.path.exists(image_path):
+            os.remove(image_path)
-- 
2.33.0



More information about the U-Boot mailing list