Debian Codegraph @

features/runner.use_substep_dirs.feature

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