Fail a testcase if it fails in teardown
Check if we have a failure in the teardown. If so, overwrite the result with the fail. Change-Id: I54ab47a30f88b7ce5837ddf0f1225fcbca53c7c5 Signed-off-by: jpike <jason.pike@windriver.com>
This commit is contained in:
@@ -33,12 +33,23 @@ class ResultCollector:
|
|||||||
"""
|
"""
|
||||||
outcome = yield
|
outcome = yield
|
||||||
report = outcome.get_result()
|
report = outcome.get_result()
|
||||||
if report.when == "call":
|
|
||||||
|
if report.when == "setup":
|
||||||
|
self.test_executor_summary.set_last_result(None)
|
||||||
|
elif report.when == "call":
|
||||||
|
self.test_executor_summary.set_last_result(report.outcome.upper())
|
||||||
|
# create final test result and update db if needed
|
||||||
|
elif report.when == "teardown":
|
||||||
|
# if the teardown failed, update the result of the test
|
||||||
|
if report.outcome.upper() == "FAILED":
|
||||||
|
self.test_executor_summary.set_last_result(report.outcome.upper())
|
||||||
self.test_executor_summary.increment_test_index()
|
self.test_executor_summary.increment_test_index()
|
||||||
self.test_executor_summary.append_tests_summary(f"{report.outcome} " f"{item.nodeid}")
|
self.test_executor_summary.append_tests_summary(f"{self.test_executor_summary.get_last_result()} " f"{item.nodeid}")
|
||||||
|
|
||||||
|
# update db if configured
|
||||||
if ConfigurationManager.get_database_config().use_database():
|
if ConfigurationManager.get_database_config().use_database():
|
||||||
self.update_result_in_database(
|
self.update_result_in_database(
|
||||||
report.outcome.upper(),
|
self.test_executor_summary.get_tests_summary(),
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_result_in_database(self, outcome: any):
|
def update_result_in_database(self, outcome: any):
|
||||||
|
@@ -1,8 +1,12 @@
|
|||||||
class TestExecutorSummary:
|
class TestExecutorSummary:
|
||||||
|
"""
|
||||||
|
Test Executor class
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.test_index = 1
|
self.test_index: int = 1
|
||||||
self.tests_summary = []
|
self.tests_summary: list[str] = []
|
||||||
|
self.last_result: str | None = None
|
||||||
|
|
||||||
def increment_test_index(self):
|
def increment_test_index(self):
|
||||||
"""
|
"""
|
||||||
@@ -23,6 +27,7 @@ class TestExecutorSummary:
|
|||||||
def append_tests_summary(self, test_summary: str):
|
def append_tests_summary(self, test_summary: str):
|
||||||
"""
|
"""
|
||||||
This function will add the test_summary specified to the stored list of tests_summary
|
This function will add the test_summary specified to the stored list of tests_summary
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
test_summary (str): The summary line to add.
|
test_summary (str): The summary line to add.
|
||||||
Returns: None
|
Returns: None
|
||||||
@@ -30,10 +35,44 @@ class TestExecutorSummary:
|
|||||||
"""
|
"""
|
||||||
self.tests_summary.append(test_summary)
|
self.tests_summary.append(test_summary)
|
||||||
|
|
||||||
def get_tests_summary(self) -> [str]:
|
def set_tests_summary(self, test_summary: [str]):
|
||||||
|
"""
|
||||||
|
Sets the test summary
|
||||||
|
|
||||||
|
Args:
|
||||||
|
test_summary ([str]): the summary lines to set.
|
||||||
|
|
||||||
|
"""
|
||||||
|
self.tests_summary = test_summary
|
||||||
|
|
||||||
|
def get_tests_summary(self) -> list[str]:
|
||||||
"""
|
"""
|
||||||
Getter for the tests_summary
|
Getter for the tests_summary
|
||||||
Returns: A list of Strings.
|
|
||||||
|
Returns:
|
||||||
|
list[str]: A list of Strings.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self.tests_summary
|
return self.tests_summary
|
||||||
|
|
||||||
|
def set_last_result(self, last_result: str | None):
|
||||||
|
"""
|
||||||
|
Sets the last_result
|
||||||
|
|
||||||
|
Args:
|
||||||
|
last_result (str | None): the last result
|
||||||
|
|
||||||
|
Returns: None
|
||||||
|
|
||||||
|
"""
|
||||||
|
self.last_result = last_result
|
||||||
|
|
||||||
|
def get_last_result(self) -> str | None:
|
||||||
|
"""
|
||||||
|
Gets the last result
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str | None: the last result
|
||||||
|
|
||||||
|
"""
|
||||||
|
return self.last_result
|
||||||
|
Reference in New Issue
Block a user