Debian Codegraph @

features/runner.select_scenarios_by_file_location.feature

raw
1 @sequential
2 Feature: Select Scenarios by File Location
3
4 To simplify running only one scenario in a feature (or some scenarios)
5 As a tester
6 I want to select a scenario by using its file location,
7 like: "alice.feature:10" (schema: {filename}:{line})
8
9
10 . CONCEPT: File Location
11 . * A file location consists of file name and a positive line number
12 . * A file location is represented as "{filename}:{line}" (or "{filename}")
13 . * A file location with filename but without line number
14 . refers to the complete file
15 . * A file location with line number 0 (zero) refers to the complete file
16 .
17 . SPECIFICATION: Scenario selection by file locations
18 . * scenario.line == file_location.line selects scenario (preferred method).
19 . * Any line number in the following range is acceptable:
20 . scenario.line <= file_location.line < next_scenario.line
21 . * The first scenario is selected,
22 . if the file location line number is less than first scenario.line.
23 . * The last scenario is selected,
24 . if the file location line number is greater than the lines in the file.
25 .
26 . SPECIFICATION: Runner with scenario locations (file locations)
27 . * Adjacent file locations are merged if they refer to the same file, like:
28 .
29 . alice.feature:10
30 . alice.feature:20
31 .
32 . => MERGED: Selects/runs "alice.feature" with 2 scenarios.
33 .
34 . alice.feature
35 . alice.feature:20
36 .
37 . => MERGED: Selects "alice.feature" with all scenarios.
38 .
39 . alice.feature:10
40 . bob.feature:20
41 . alice.feature:20
42 .
43 . => NOT MERGED: Selects/runs "alice.feature" twice.
44 .
45 . * If file locations (scenario locations) are used,
46 . scenarios with @setup or @teardown tags are selected, too.
47 .
48 . REASON: Simplifies to use a Setup Scenario instead of a Background.
49 .
50 . * Additional scenario selection mechanisms, like tags, names,
51 . are applied afterwards.
52
53
54 @setup
55 Scenario: Feature Setup
56 Given a new working directory
57 And a file named "features/steps/steps.py" with:
58 """
59 from behave import step
60
61 @step('a step passes')
62 def step_passes(context):
63 pass
64 """
65 And a file named "features/alice.feature" with:
66 """
67 Feature: Alice
68
69 Scenario: Alice First
70 When a step passes
71
72 Scenario: Alice Last
73 Then a step passes
74 """
75 And a file named "features/bob.feature" with:
76 """
77 Feature: Bob
78
79 @setup
80 Scenario: Setup Bob
81 Given a step passes
82
83 Scenario: Bob in Berlin
84 When a step passes
85
86 Scenario: Bob in Paris
87 Then a step passes
88
89 @teardown
90 Scenario: Teardown Bob
91 Then a step passes
92 """
93 And a file named "behave.ini" with:
94 """
95 [behave]
96 show_skipped = false
97 show_timings = false
98 """
99
100
101 @file_location.select
102 Scenario: Select one scenario with its exact file location
103
104 CASE: scenario.line == file_location.line
105
106 When I run "behave -f plain --dry-run --no-skipped features/alice.feature:3"
107 Then it should pass with:
108 """
109 0 features passed, 0 failed, 0 skipped, 1 untested
110 0 scenarios passed, 0 failed, 1 skipped, 1 untested
111 """
112 And the command output should contain:
113 """
114 Feature: Alice
115 Scenario: Alice First
116 """
117 But the command output should not contain:
118 """
119 Scenario: Alice Last
120 """
121
122 @file_location.select
123 Scenario: Select one scenario with a larger file location
124
125 CASE: scenario.line <= file_location.line < next_scenario.line
126
127 When I run "behave -f plain --dry-run --no-skipped features/alice.feature:4"
128 Then it should pass with:
129 """
130 0 features passed, 0 failed, 0 skipped, 1 untested
131 0 scenarios passed, 0 failed, 1 skipped, 1 untested
132 """
133 And the command output should contain:
134 """
135 Feature: Alice
136 Scenario: Alice First
137 """
138 But the command output should not contain:
139 """
140 Scenario: Alice Last
141 """
142
143 @file_location.select
144 Scenario: Select next scenario with its exact location
145
146 CASE: scenario.line < file_location.line == next_scenario.line
147
148 When I run "behave -f plain --dry-run --no-skipped features/alice.feature:6"
149 Then it should pass with:
150 """
151 0 features passed, 0 failed, 0 skipped, 1 untested
152 0 scenarios passed, 0 failed, 1 skipped, 1 untested
153 """
154 And the command output should contain:
155 """
156 Feature: Alice
157 Scenario: Alice Last
158 """
159 But the command output should not contain:
160 """
161 Scenario: Alice First
162 """
163
164 @file_location.select_first
165 Scenario: Select first scenario if line number is smaller than first scenario line
166
167 CASE: 0 < file_location.line < first_scenario.line
168
169 When I run "behave -f plain --dry-run --no-skipped features/alice.feature:1"
170 Then it should pass with:
171 """
172 0 features passed, 0 failed, 0 skipped, 1 untested
173 0 scenarios passed, 0 failed, 1 skipped, 1 untested
174 """
175 And the command output should contain:
176 """
177 Feature: Alice
178 Scenario: Alice First
179 """
180 But the command output should not contain:
181 """
182 Scenario: Alice Last
183 """
184
185 @file_location.select_last
186 Scenario: Select last scenario when line number is too large
187
188 CASE: last_scenario.line < file.last_line < file_location.line
189
190 When I run "behave -f plain --dry-run --no-skipped features/alice.feature:100"
191 Then it should pass with:
192 """
193 0 features passed, 0 failed, 0 skipped, 1 untested
194 0 scenarios passed, 0 failed, 1 skipped, 1 untested
195 """
196 And the command output should contain:
197 """
198 Feature: Alice
199 Scenario: Alice Last
200 """
201 But the command output should not contain:
202 """
203 Scenario: Alice First
204 """
205
206
207 @file_location.select_all
208 Scenario: Select all scenarios with line number 0 (zero)
209 When I run "behave -f plain --dry-run --no-skipped features/alice.feature:0"
210 Then it should pass with:
211 """
212 0 features passed, 0 failed, 0 skipped, 1 untested
213 0 scenarios passed, 0 failed, 0 skipped, 2 untested
214 """
215 And the command output should contain "Scenario: Alice First"
216 And the command output should contain "Scenario: Alice Last"
217 But note that "all scenarios of this features are selected"
218
219
220 @file_location.select
221 @with.feature_configfile
222 Scenario: Select a scenario by using file locations from a features configfile
223 Given a file named "alice1.txt" with:
224 """
225 # -- FEATURES CONFIGFILE:
226 # Selects Alice First
227 features/alice.feature:3
228 """
229 When I run "behave -f plain --dry-run --no-skipped @alice1.txt"
230 Then it should pass with:
231 """
232 0 features passed, 0 failed, 0 skipped, 1 untested
233 0 scenarios passed, 0 failed, 1 skipped, 1 untested
234 """
235 And the command output should contain:
236 """
237 Feature: Alice
238 Scenario: Alice First
239 """
240 But the command output should not contain:
241 """
242 Scenario: Alice Last
243 """
244
245 @file_location.autoselect_setup_teardown
246 Scenario: Auto-select scenarios tagged with @setup or @teardown if file location is used
247 When I run "behave -f plain --dry-run --no-skipped features/bob.feature:7"
248 Then it should pass with:
249 """
250 0 features passed, 0 failed, 0 skipped, 1 untested
251 0 scenarios passed, 0 failed, 1 skipped, 3 untested
252 """
253 And the command output should contain "Scenario: Setup Bob"
254 And the command output should contain "Scenario: Bob in Berlin"
255 And the command output should contain "Scenario: Teardown Bob"
256 But the command output should not contain "Scenario: Bob in Paris"
257
258 @merge.file_locations
259 Scenario: Merge 2 adjacent file locations that refer to the same file
260 When I run "behave -f plain --dry-run --no-skipped features/alice.feature:3 features/alice.feature:6"
261 Then it should pass with:
262 """
263 0 features passed, 0 failed, 0 skipped, 1 untested
264 0 scenarios passed, 0 failed, 0 skipped, 2 untested
265 """
266 And the command output should contain:
267 """
268 Feature: Alice
269 Scenario: Alice First
270 When a step passes ... untested
271
272 Scenario: Alice Last
273 Then a step passes ... untested
274 """
275 But the command output should not contain:
276 """
277 Feature: Alice
278 Scenario: Alice First
279 When a step passes ... untested
280
281 Feature: Alice
282 Scenario: Alice Last
283 """
284 And note that "both file locations are merged"
285
286
287 @merge.file_locations
288 @file_location.select_all
289 Scenario: Merge filename and adjacent file location that refer to the same file
290 When I run "behave -f plain --dry-run --no-skipped features/alice.feature:3 features/alice.feature"
291 Then it should pass with:
292 """
293 0 features passed, 0 failed, 0 skipped, 1 untested
294 0 scenarios passed, 0 failed, 0 skipped, 2 untested
295 """
296 And the command output should contain:
297 """
298 Feature: Alice
299 Scenario: Alice First
300 When a step passes ... untested
301
302 Scenario: Alice Last
303 Then a step passes ... untested
304 """
305 But the command output should not contain:
306 """
307 Feature: Alice
308 Scenario: Alice First
309 When a step passes ... untested
310
311 Feature: Alice
312 Scenario: Alice First
313 When a step passes ... untested
314
315 Scenario: Alice Last
316 Then a step passes ... untested
317 """
318 And note that "duplicated file locations are removed in the merge"
319
320
321 @merge.file_locations
322 @with.feature_listfile
323 Scenario: Merge 2 adjacent file locations to same file from features-listfile
324 Given a file named "alice1_and_alice2.txt" with:
325 """
326 # -- FEATURES CONFIGFILE:
327 # Selects Alice First, Alice Last
328 features/alice.feature:3
329 features/alice.feature:6
330 """
331 When I run "behave -f plain --dry-run --no-skipped @alice1_and_alice2.txt"
332 Then it should pass with:
333 """
334 0 features passed, 0 failed, 0 skipped, 1 untested
335 0 scenarios passed, 0 failed, 0 skipped, 2 untested
336 """
337 And the command output should contain:
338 """
339 Feature: Alice
340 Scenario: Alice First
341 When a step passes ... untested
342
343 Scenario: Alice Last
344 Then a step passes ... untested
345 """
346 But the command output should not contain:
347 """
348 Feature: Alice
349 Scenario: Alice First
350 When a step passes ... untested
351
352 Feature: Alice
353 Scenario: Alice Last
354 Then a step passes ... untested
355 """
356
357 @no_merge.file_locations
358 @with.feature_listfile
359 Scenario: No merge occurs if file locations to same file are not adjacent
360 Given a file named "alice1_bob2_and_alice2.txt" with:
361 """
362 # -- FEATURES CONFIGFILE:
363 # Selects Alice First, Bob in Paris (Setup, Teardown), Alice Last
364 features/alice.feature:3
365 features/bob.feature:10
366 features/alice.feature:6
367 """
368 When I run "behave -f plain --dry-run --no-skipped @alice1_bob2_and_alice2.txt"
369 Then it should pass with:
370 """
371 0 features passed, 0 failed, 0 skipped, 3 untested
372 0 scenarios passed, 0 failed, 3 skipped, 5 untested
373 """
374 And the command output should contain:
375 """
376 Feature: Alice
377 Scenario: Alice First
378 When a step passes ... untested
379
380 Feature: Bob
381 Scenario: Setup Bob
382 Given a step passes ... untested
383
384 Scenario: Bob in Paris
385 Then a step passes ... untested
386
387 Scenario: Teardown Bob
388 Then a step passes ... untested
389
390 Feature: Alice
391 Scenario: Alice Last
392 Then a step passes ... untested
393 """
394 But the command output should not contain:
395 """
396 Feature: Alice
397 Scenario: Alice First
398 When a step passes ... untested
399
400 Scenario: Alice Last
401 Then a step passes ... untested
402 """
403 And note that "non-adjacent file locations to the same file are not merged"