Let me improve @Barry's answer:
Basically, what he suggested (i.e. scenario.mark_skipped() ) is:
scenario.skip(require_not_executed=True)
To be precise, the mark_skipped() 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 this:
def skip(self, reason=None, require_not_executed=False)
A few things:
require_not_executed=True means that the script cannot be skipped if any step has already passed, i.e. mark_skipped() at the second or later stage throws an exception and then skips all the steps after that, and not just skips the next stepsskip() allows you to specify a skip reason, which is then registered as WARN .
In addition, the scenario object is available in context as context.scenario (next to context.feature ).
Ultimately, a 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
m4tx
source share