You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not all cleanup functions for the scenario will get called (except Exception does not catch KeyboardInterrupt and aborts the loop)
The testrun layer of the context does not have its @cleanups run.
Problem 1 can be solved by changing Exception to BaseException (simple) so that the loop doesn't terminate, though the cleanup_func can still be interrupted:
diff --git a/behave/runner.py b/behave/runner.py
index 1f32ec1..5e5c4f5 100644
--- a/behave/runner.py+++ b/behave/runner.py@@ -225,7 +225,7 @@ class Context(object):
for cleanup_func in reversed(cleanup_funcs):
try:
cleanup_func()
- except Exception as e: # pylint: disable=broad-except+ except BaseException as e: # pylint: disable=broad-except
# pylint: disable=protected-access
context._root["cleanup_errors"] += 1
cleanup_errors.append(sys.exc_info())
OR by writing more complex logic to disable/defer SIGINT while cleanups are running so that they are uninterruptible.
I will need to monkey patch Behave to solve Problem 1 for now.
Problem 2 can be solved in user space with the following after_all check:
OR by explicitly _poping the feature layer from the context stack when a KeyboardInterrupt is received (simple):
diff --git a/behave/runner.py b/behave/runner.py
index 1f32ec1..4461d78 100644
--- a/behave/runner.py+++ b/behave/runner.py@@ -698,6 +698,9 @@ class ModelRunner(object):
self.aborted = True
failed_count += 1
run_feature = False
+ # -- Pop the feature layer if interrupted before feature.run() did so+ if self.context._stack[0].get("@layer", "") == "feature":+ self.context._stack.pop()
# -- ALWAYS: Report run/not-run feature to reporters.
# REQUIRED-FOR: Summary to keep track of untested features.
OR by rewriting context._push to return a context manager that guarantees that the stack entry will be popped in a finally block (more complex/requires more code change).
I am curious what you think is the best way forward here.
The text was updated successfully, but these errors were encountered:
From my testing, it seems that if a
KeyboardInterrupt
occurs during cleanup of a scenario:behave/behave/runner.py
Lines 226 to 228 in 61781ed
Then there are two negative consequences:
except Exception
does not catchKeyboardInterrupt
and aborts the loop)testrun
layer of the context does not have its@cleanups
run.Problem 1 can be solved by changing
Exception
toBaseException
(simple) so that the loop doesn't terminate, though thecleanup_func
can still be interrupted:OR by writing more complex logic to disable/defer SIGINT while cleanups are running so that they are uninterruptible.
I will need to monkey patch Behave to solve Problem 1 for now.
Problem 2 can be solved in user space with the following
after_all
check:OR by explicitly
_pop
ing thefeature
layer from the context stack when aKeyboardInterrupt
is received (simple):OR by rewriting
context._push
to return a context manager that guarantees that the stack entry will be popped in afinally
block (more complex/requires more code change).I am curious what you think is the best way forward here.
The text was updated successfully, but these errors were encountered: