diff mbox series

tests: Fix exception when cleaning up skipped test

Message ID 20230703133518.3879199-1-JPEWhacker@gmail.com
State Accepted
Commit 8900ba1ad7cbe5ad143c39635e93f7c3b1d41460
Delegated to: Tom Rini
Headers show
Series tests: Fix exception when cleaning up skipped test | expand

Commit Message

Joshua Watt July 3, 2023, 1:35 p.m. UTC
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@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(-)

Comments

Simon Glass July 4, 2023, 2:40 a.m. UTC | #1
On Mon, 3 Jul 2023 at 14:35, Joshua Watt <jpewhacker@gmail.com> wrote:
>
> 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@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(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini July 18, 2023, 1:58 p.m. UTC | #2
On Mon, Jul 03, 2023 at 08:35:09AM -0500, Joshua Watt wrote:

> 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@gmail.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

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)