Skip to content

Instantly share code, notes, and snippets.

@curzona
Created March 5, 2016 11:24
Show Gist options
  • Save curzona/5d71062aaecd1b5d0408 to your computer and use it in GitHub Desktop.
Save curzona/5d71062aaecd1b5d0408 to your computer and use it in GitHub Desktop.
behave example
# -- FILE: features/steps/example_steps.py
from behave import given, when, then, step
import time
@given('we have behave installed')
def step_impl(context):
time.sleep(1)
@when('we implement {number:d} tests')
def step_impl(context, number): # -- NOTE: number is converted into integer
assert number > 1 or number == 0
context.tests_count = number
time.sleep(1)
@then('behave will test them for us!')
def step_impl(context):
assert context.failed is False
assert context.tests_count >= 0
time.sleep(1)
@then("behave will yell and scream")
def step_impl(context):
time.sleep(1)
assert False
Feature: Showing off behave # features/example.feature:2
Scenario: Run a simple test # features/example.feature:4
Given we have behave installed # features/steps/example_steps.py:5 1.001s
When we implement 5 tests # features/steps/example_steps.py:9 1.001s
Then behave will test them for us! # features/steps/example_steps.py:15 1.001s
Scenario: Run another simple test # features/example.feature:9
Given we have behave installed # features/steps/example_steps.py:5 1.001s
When we implement 0 tests # features/steps/example_steps.py:9 1.001s
Then behave will yell and scream # features/steps/example_steps.py:21 1.001s
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/behave/model.py", line 1456, in run
match.run(runner.context)
File "/usr/local/lib/python2.7/dist-packages/behave/model.py", line 1903, in run
self.func(context, *args, **kwargs)
File "features/steps/example_steps.py", line 24, in step_impl
assert False
AssertionError
Failing scenarios:
features/example.feature:9 Run another simple test
0 features passed, 1 failed, 0 skipped
1 scenario passed, 1 failed, 0 skipped
5 steps passed, 1 failed, 0 skipped, 0 undefined
Took 0m6.007s
# -- FILE: features/example.feature
Feature: Showing off behave
Scenario: Run a simple test
Given we have behave installed
When we implement 5 tests
Then behave will test them for us!
Scenario: Run another simple test
Given we have behave installed
When we implement 0 tests
Then behave will yell and scream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment