1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
Feature: Use substep directories
As a behave user
I want to use a deep, hierarchical steps dir,
meaning steps from subdirs of the steps directory,
So that the steps directory structure is more cleaned up.
. HINT:
. If you really have so many step modules,
. better use step-libraries, instead (in many cases).
.
. REQUIRES: path.py
Background:
Given a new working directory
And a file named "features/steps/use_substep_dirs.py" with:
"""
# -- REQUIRES: path.py
# from __future__ import absolute_import
from behave.runner_util import load_step_modules
from path import Path
HERE = Path(__file__).dirname()
SUBSTEP_DIRS = list(HERE.walkdirs())
load_step_modules(SUBSTEP_DIRS)
"""
And a file named "behave.ini" with:
"""
[behave]
default_format = pretty
color = False
"""
Scenario: Use one substep directory
Given a file named "features/steps/alice_steps.py" with:
"""
from behave import step
@step('I know Alice')
def step_i_know_alice(context):
pass
"""
And a file named "features/steps/foo/bob_steps.py" with:
"""
from behave import step
@step('I know Bob')
def step_i_know_bob(context):
pass
"""
And a file named "features/use_substeps1.feature" with:
"""
Feature:
Scenario:
Given I know Alice
And I know Bob
"""
When I run "behave features/use_substeps1.feature"
Then it should pass with:
"""
1 scenario passed, 0 failed, 0 skipped
2 steps passed, 0 failed, 0 skipped, 0 undefined
"""
And the command output should contain:
"""
Feature: # features/use_substeps1.feature:1
Scenario: # features/use_substeps1.feature:2
Given I know Alice # features/steps/alice_steps.py:3
And I know Bob # features/steps/foo/bob_steps.py:3
"""
Scenario: Use two substep directories
Given a file named "features/steps/alice_steps.py" with:
"""
from behave import step
@step('I know Alice')
def step_i_know_alice(context):
pass
"""
And a file named "features/steps/foo/bob_steps.py" with:
"""
from behave import step
@step('I know Bob')
def step_i_know_bob(context):
pass
"""
And a file named "features/steps/bar/baz/charly_steps.py" with:
"""
from behave import step
@step('I know Charly2')
def step_i_know_charly2(context):
pass
"""
And a file named "features/use_substeps2.feature" with:
"""
Feature:
Scenario:
Given I know Alice
And I know Bob
And I know Charly2
"""
When I run "behave features/use_substeps2.feature"
Then it should pass with:
"""
1 scenario passed, 0 failed, 0 skipped
3 steps passed, 0 failed, 0 skipped, 0 undefined
"""
And the command output should contain:
"""
Feature: # features/use_substeps2.feature:1
Scenario: # features/use_substeps2.feature:2
Given I know Alice # features/steps/alice_steps.py:3
And I know Bob # features/steps/foo/bob_steps.py:3
And I know Charly2 # features/steps/bar/baz/charly_steps.py:3
"""
Scenario: Use one substep package directory
Ensure that a dummy "__init__.py" does not cause any problems.
Given a file named "features/steps/alice_steps.py" with:
"""
from behave import step
@step('I know Alice')
def step_i_know_alice(context):
pass
"""
And an empty file named "features/steps/foo/__init__.py"
And a file named "features/steps/foo/bob_steps.py" with:
"""
from behave import step
@step('I know Bobby')
def step_i_know_bob(context):
pass
"""
And a file named "features/use_substeps3.feature" with:
"""
Feature:
Scenario:
Given I know Alice
And I know Bobby
"""
When I run "behave features/use_substeps3.feature"
Then it should pass with:
"""
1 scenario passed, 0 failed, 0 skipped
2 steps passed, 0 failed, 0 skipped, 0 undefined
"""
And the command output should contain:
"""
Feature: # features/use_substeps3.feature:1
Scenario: # features/use_substeps3.feature:2
Given I know Alice # features/steps/alice_steps.py:3
And I know Bobby # features/steps/foo/bob_steps.py:3
"""
|