Skip to content

Commit

Permalink
By optimizing if, else, and using the get method, we can avoid trigge…
Browse files Browse the repository at this point in the history
…ring errors in states that do not exist in the dictionary

Signed-off-by: mataotao <[email protected]>
  • Loading branch information
mataotao committed Jun 21, 2024
1 parent 867dc7a commit 4fff7a5
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions avocado/core/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,16 @@ def check_test(self, state):
:param test: A dict with test internal state
"""
status = state.get("status")
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
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)
else:
self.errors += 1
self.end_test(state)
Expand Down

0 comments on commit 4fff7a5

Please sign in to comment.