Let me improve @Barry's answer:
Basically, what he proposed (i.e. scenario.mark_skipped()
) is equal to:
scenario.skip(require_not_executed=True)
To be exact, mark_skipped()
's source looks like this:
def mark_skipped(self):
"""Marks this scenario (and all its steps) as skipped.
Note that this method can be called before the scenario is executed.
"""
self.skip(require_not_executed=True)
assert self.status == "skipped", "OOPS: scenario.status=%s" % self.status
skip()
is defined like so:
def skip(self, reason=None, require_not_executed=False)
A few things:
require_not_executed=True
means that scenario cannot be skipped if any step has already passed, i.e. mark_skipped()
in second or later step will throw an Exception and then skip all the steps afterwards, instead of just skipping the further steps
skip()
allows to provide a reason for skipping, which is then logged as WARN
.
Furthermore, scenario
object is available in context as context.scenario
(alongside context.feature
).
Ultimately, simple example:
@given("test photos in upload directory")
def step_impl(context):
if not connection_available():
context.scenario.skip(reason='internet connection is unavailable')
Result:
Skipped: skipped
WARNING:behave:SKIP Scenario Retrieving uploaded photo details: internet connection is unavailable