Skip to contentSkip to conversation

tests: Fix exception when cleaning up skipped test

PATCH In review Joshua Watt 3 participants 3 messages Jul 3, 2023 – Jul 18, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests: Fix exception when cleaning up skipped test

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.

---
 test/py/tests/test_cat/conftest.py | 3 ++-
 test/py/tests/test_xxd/conftest.py | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
test/py/tests/test_cat/conftest.py +2 -1
index 058fe52352..ef1c54d513 100644
@@ -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)
test/py/tests/test_xxd/conftest.py +2 -1
index 59285aadf4..481a794961 100644
@@ -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)
Signature · 1 line
2.33.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Joshua Watt

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.

---
 test/py/tests/test_cat/conftest.py | 3 ++-
 test/py/tests/test_xxd/conftest.py | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
#2 lore raw
In reply to Joshua Watt
Quoted 7 lines · Joshua Watt

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.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom