@@ -51,13 +51,15 @@ publish_article.feature:
51
51
Feature: Blog
52
52
A site where you can publish your articles.
53
53
54
- Scenario: Publishing the article
55
- Given I'm an author user
56
- And I have an article
57
- When I go to the article page
58
- And I press the publish button
59
- Then I should not see the error message
60
- And the article should be published # Note: will query the database
54
+ Scenario: Publishing the article
55
+ Given I'm an author user
56
+ And I have an article
57
+
58
+ When I go to the article page
59
+ And I press the publish button
60
+
61
+ Then I should not see the error message
62
+ And the article should be published # Note: will query the database
61
63
62
64
Note that only one feature is allowed per feature file.
63
65
@@ -150,14 +152,15 @@ default author.
150
152
151
153
.. code-block :: gherkin
152
154
153
- Scenario: I'm the author
154
- Given I'm an author
155
- And I have an article
155
+ Feature: Resource owner
156
+ Scenario: I'm the author
157
+ Given I'm an author
158
+ And I have an article
156
159
157
160
158
- Scenario: I'm the admin
159
- Given I'm the admin
160
- And there's an article
161
+ Scenario: I'm the admin
162
+ Given I'm the admin
163
+ And there's an article
161
164
162
165
163
166
Given step scope
@@ -174,14 +177,15 @@ pass optional ``scope`` argument:
174
177
175
178
.. code-block :: gherkin
176
179
177
- Scenario: I'm the author
178
- Given I'm an author
179
- And there is an article
180
+ Feature: Fixture scope
181
+ Scenario: I'm the author
182
+ Given I'm an author
183
+ And there is an article
180
184
181
185
182
- Scenario: I'm the admin
183
- Given I'm the admin
184
- And there is an article
186
+ Scenario: I'm the admin
187
+ Given I'm the admin
188
+ And there is an article
185
189
186
190
187
191
In this example, the step function for the 'there is an article' given step will be executed once, even though there
@@ -257,13 +261,14 @@ Example:
257
261
258
262
.. code-block :: gherkin
259
263
260
- Scenario: Arguments for given, when, thens
261
- Given there are 5 cucumbers
264
+ Feature: Step arguments
265
+ Scenario: Arguments for given, when, thens
266
+ Given there are 5 cucumbers
262
267
263
- When I eat 3 cucumbers
264
- And I eat 2 cucumbers
268
+ When I eat 3 cucumbers
269
+ And I eat 2 cucumbers
265
270
266
- Then I should have 0 cucumbers
271
+ Then I should have 0 cucumbers
267
272
268
273
269
274
The code will look like:
@@ -367,9 +372,10 @@ it will stay untouched. To allow this, special parameter `target_fixture` exists
367
372
368
373
.. code-block :: gherkin
369
374
370
- Scenario: Test given fixture injection
371
- Given I have injecting given
372
- Then foo should be "injected foo"
375
+ Feature: Target fixture
376
+ Scenario: Test given fixture injection
377
+ Given I have injecting given
378
+ Then foo should be "injected foo"
373
379
374
380
In this example existing fixture `foo ` will be overridden by given step `I have injecting given ` only for scenario it's
375
381
used in.
@@ -384,12 +390,13 @@ But in much cleaner and powerful way:
384
390
385
391
.. code-block :: gherkin
386
392
387
- Scenario: Multiline step using sub indentation
388
- Given I have a step with:
389
- Some
390
- Extra
391
- Lines
392
- Then the text should be parsed with correct indentation
393
+ Feature: Multiline steps
394
+ Scenario: Multiline step using sub indentation
395
+ Given I have a step with:
396
+ Some
397
+ Extra
398
+ Lines
399
+ Then the text should be parsed with correct indentation
393
400
394
401
Step is considered as multiline one, if the **next ** line(s) after it's first line, is indented relatively
395
402
to the first line. The step name is then simply extended by adding further lines with newlines.
@@ -489,29 +496,31 @@ Example:
489
496
490
497
.. code-block :: gherkin
491
498
492
- Scenario Outline: Outlined given, when, thens
493
- Given there are <start> cucumbers
494
- When I eat <eat> cucumbers
495
- Then I should have <left> cucumbers
499
+ Feature: Scenario outlines
500
+ Scenario Outline: Outlined given, when, thens
501
+ Given there are <start> cucumbers
502
+ When I eat <eat> cucumbers
503
+ Then I should have <left> cucumbers
496
504
497
- Examples:
498
- | start | eat | left |
499
- | 12 | 5 | 7 |
505
+ Examples:
506
+ | start | eat | left |
507
+ | 12 | 5 | 7 |
500
508
501
509
pytest-bdd feature file format also supports example tables in different way:
502
510
503
511
504
512
.. code-block :: gherkin
505
513
506
- Scenario Outline: Outlined given, when, thens
507
- Given there are <start> cucumbers
508
- When I eat <eat> cucumbers
509
- Then I should have <left> cucumbers
514
+ Feature: Scenario outlines
515
+ Scenario Outline: Outlined given, when, thens
516
+ Given there are <start> cucumbers
517
+ When I eat <eat> cucumbers
518
+ Then I should have <left> cucumbers
510
519
511
- Examples: Vertical
512
- | start | 12 | 2 |
513
- | eat | 5 | 1 |
514
- | left | 7 | 1 |
520
+ Examples: Vertical
521
+ | start | 12 | 2 |
522
+ | eat | 5 | 1 |
523
+ | left | 7 | 1 |
515
524
516
525
This form allows to have tables with lots of columns keeping the maximum text width predictable without significant
517
526
readability change.
@@ -782,8 +791,10 @@ This also declares a PyTest fixture "article" and any other step can depend on i
782
791
783
792
.. code-block :: gherkin
784
793
785
- Given I have a beautiful article
786
- When I publish this article
794
+ Feature: Power of pytest
795
+ Scenario: Symbolic name across steps
796
+ Given I have a beautiful article
797
+ When I publish this article
787
798
788
799
When step is referring the article to publish it.
789
800
@@ -831,9 +842,11 @@ no sense. It won't be executed second time.
831
842
832
843
.. code-block :: gherkin
833
844
834
- Given I have a beautiful article
835
- And some other thing
836
- And I have a beautiful article # Won't be executed, exception is raised
845
+ Feature: Power of pytest
846
+ Scenario: Given is a fixture and evaluated only once
847
+ Given I have a beautiful article
848
+ And some other thing
849
+ And I have a beautiful article # Won't be executed, exception is raised
837
850
838
851
839
852
pytest-bdd will raise an exception even in the case of the steps that use regular expression
@@ -842,8 +855,10 @@ patterns to get arguments.
842
855
843
856
.. code-block :: gherkin
844
857
845
- Given I have 1 cucumbers
846
- And I have 2 cucumbers # Exception is raised
858
+ Feature: Power of pytest
859
+ Scenario: Given is a fixture and evaluated only once
860
+ Given I have 1 cucumbers
861
+ And I have 2 cucumbers # Exception is raised
847
862
848
863
Will raise an exception if the step is using the regular expression pattern.
849
864
0 commit comments