Consider the following feature test for Behave:
Feature: Student
Scenario Outline: New
Given User <cn> created in YAML
Then Verify cn matches "<cn>"
Then Verify sn matches "<sn>"
Then Verify givenName matches "<givenName>"
Examples:
| cn | sn | givenName |
| blewis1 | Lewis | Bob |
| asmith2 | Smith | Alan |
The ultimate goal is to verify the above attributes in LDAP with the correct values contained in a YAML input file. There are a few users and attributes so a YAML file is easier to manage. I tried the following:
[features/test.feature]
Feature: Student
Scenario Outline: New
Given User <cn> created in YAML
Then Verify cn matches "<cn>"
Then Verify sn matches "<sn>"
Then Verify givenName matches "<givenName>"
[features/test.yml]
blewis1:
cn: blewis1
sn: Lewis
givenName: Bob
asmith2:
cn: asmith2
sn: Smith
givenName: Alan
[features/steps/steps.py]
import yaml
from behave import given, then
@given('User {user} created in YAML')
def search_user (context, user):
with open ('features/test.yml', 'r') as config_fh:
user_data = yaml.safe_load (config_fh)
if user in user_data:
context.user_entry = {}
for attrib in ['cn', 'givenName', 'sn']:
context.user_entry[attrib] = user_data[user][attrib]
print (context.user_entry)
assert (user == context.user_entry['cn'])
@then('Verify {attrib} matches "{value}"')
def check_attribute (context, attrib, value):
assert (context.user_entry[attrib] == value)
If I try to run features/test.feature through Behave:
$ behave features/test.feature --no-source --no-timings
--no-summary --no-capture --no-capture-stderr
Feature: Student
The scenario outline is not run. Looks like the lack of Examples means scenario outline is ignored. Any ideas? Maybe I just need to override how templates are rendered?