Skip to content

Commit

Permalink
INTERRUPTED status overwrite fix
Browse files Browse the repository at this point in the history
When avocado-instrumented test is interrupted, the avocado runner will
call a tearDown method to clean the test environment. If some error is
raised during the tearDown phase, the `INTERRUPTED` status is
overwritten by this error. This is not desired behavior, because the
reason for the error was interruption of the test. This fix keeps
logging of the tearDown error without change of the `INTERRUPTED`
status.

Reference: avocado-framework#5801
Signed-off-by: Jan Richter <jarichte@redhat.com>
  • Loading branch information
richtja committed Nov 20, 2023
1 parent 1e8315e commit ee8cb25
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
5 changes: 3 additions & 2 deletions avocado/core/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,9 @@ def _tearDown(self):
raise
except: # avoid old-style exception failures pylint: disable=W0702
stacktrace.log_exc_info(sys.exc_info(), logger=self.log)
details = sys.exc_info()[1]
raise exceptions.TestSetupFail(details)
if self.status != "INTERRUPTED":
details = sys.exc_info()[1]
raise exceptions.TestSetupFail(details)

def _setup_environment_variables(self):
os.environ["AVOCADO_VERSION"] = VERSION
Expand Down
19 changes: 19 additions & 0 deletions selftests/.data/test_statuses.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import time

from avocado import Test, skip

Expand Down Expand Up @@ -295,3 +296,21 @@ def tearDown(self):
raise ValueError
# pylint: disable=W0101
self.log.info("teardown post")


class ExceptionTeardownSleep(Test):
def setUp(self):
self.log.info("setup pre")
self.log.info("setup post")

def test(self):
self.log.info("test pre")
time.sleep(10)
self.log.info("test post")

def tearDown(self):
self.log.info("teardown pre")
self.log.info("teardown status: %s", self.status)
raise ValueError
# pylint: disable=W0101
self.log.info("teardown post")
12 changes: 11 additions & 1 deletion selftests/functional/statuses.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@
"teardown status: PASS",
],
),
"ExceptionTeardownSleep.test": (
"INTERRUPTED",
[
"setup pre",
"setup post",
"test pre",
"teardown pre",
"teardown status: INTERRUPTED",
],
),
}


Expand All @@ -187,7 +197,7 @@ def setUp(self):
)

cmd = (
f"{AVOCADO} run {test_file} --disable-sysinfo "
f"{AVOCADO} run --job-timeout=5 {test_file} --disable-sysinfo "
f"--job-results-dir {self.tmpdir.name} --json - "
)

Expand Down

0 comments on commit ee8cb25

Please sign in to comment.