Skip to content

Commit

Permalink
Add exception handling to os.remove
Browse files Browse the repository at this point in the history
Signed-off-by: mataotao <[email protected]>
  • Loading branch information
mataotao committed Jul 26, 2024
1 parent 1051bc0 commit ee32a50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
24 changes: 12 additions & 12 deletions avocado/core/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ def check_test(self, state):
:param test: A dict with test internal state
"""
status = state.get("status")
status_mapping = {
"PASS": "passed",
"SKIP": "skipped",
"FAIL": "failed",
"WARN": "warned",
"INTERRUPTED": "interrupted",
"CANCEL": "cancelled",
}
if status in status_mapping:
setattr(
self, status_mapping[status], getattr(self, status_mapping[status]) + 1
)
if status == "PASS":
self.passed += 1
elif status == "SKIP":
self.skipped += 1
elif status == "FAIL":
self.failed += 1
elif status == "WARN":
self.warned += 1
elif status == "INTERRUPTED":
self.interrupted += 1
elif status == "CANCEL":
self.cancelled += 1
else:
self.errors += 1
self.end_test(state)
Expand Down
11 changes: 8 additions & 3 deletions avocado/utils/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,14 @@ def remove_asset_by_path(cls, asset_path):
:param asset_path: full path of the asset file.
"""
os.remove(asset_path)
filename = f"{asset_path}-CHECKSUM"
os.remove(filename)
try:
os.remove(asset_path)
filename = f"{asset_path}-CHECKSUM"
os.remove(filename)
except FileNotFoundError:
LOG.error(f"File not found: {asset_path} or its checksum file.")
except Exception as e:
LOG.error(f"An error occurred while removing files: {e}")

@property
def urls(self):
Expand Down

0 comments on commit ee32a50

Please sign in to comment.