Skip to content

Commit bfefabe

Browse files
Some more test cleanup (#375)
* Some more test cleanup * Docs updated
1 parent 76ed2ec commit bfefabe

15 files changed

+674
-376
lines changed

README.rst

Lines changed: 70 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ publish_article.feature:
5151
Feature: Blog
5252
A site where you can publish your articles.
5353
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
6163
6264
Note that only one feature is allowed per feature file.
6365

@@ -150,14 +152,15 @@ default author.
150152

151153
.. code-block:: gherkin
152154
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
156159
157160
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
161164
162165
163166
Given step scope
@@ -174,14 +177,15 @@ pass optional ``scope`` argument:
174177
175178
.. code-block:: gherkin
176179
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
180184
181185
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
185189
186190
187191
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:
257261

258262
.. code-block:: gherkin
259263
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
262267
263-
When I eat 3 cucumbers
264-
And I eat 2 cucumbers
268+
When I eat 3 cucumbers
269+
And I eat 2 cucumbers
265270
266-
Then I should have 0 cucumbers
271+
Then I should have 0 cucumbers
267272
268273
269274
The code will look like:
@@ -367,9 +372,10 @@ it will stay untouched. To allow this, special parameter `target_fixture` exists
367372
368373
.. code-block:: gherkin
369374
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"
373379
374380
In this example existing fixture `foo` will be overridden by given step `I have injecting given` only for scenario it's
375381
used in.
@@ -384,12 +390,13 @@ But in much cleaner and powerful way:
384390

385391
.. code-block:: gherkin
386392
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
393400
394401
Step is considered as multiline one, if the **next** line(s) after it's first line, is indented relatively
395402
to the first line. The step name is then simply extended by adding further lines with newlines.
@@ -489,29 +496,31 @@ Example:
489496

490497
.. code-block:: gherkin
491498
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
496504
497-
Examples:
498-
| start | eat | left |
499-
| 12 | 5 | 7 |
505+
Examples:
506+
| start | eat | left |
507+
| 12 | 5 | 7 |
500508
501509
pytest-bdd feature file format also supports example tables in different way:
502510

503511

504512
.. code-block:: gherkin
505513
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
510519
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 |
515524
516525
This form allows to have tables with lots of columns keeping the maximum text width predictable without significant
517526
readability change.
@@ -782,8 +791,10 @@ This also declares a PyTest fixture "article" and any other step can depend on i
782791

783792
.. code-block:: gherkin
784793
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
787798
788799
When step is referring the article to publish it.
789800

@@ -831,9 +842,11 @@ no sense. It won't be executed second time.
831842

832843
.. code-block:: gherkin
833844
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
837850
838851
839852
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.
842855

843856
.. code-block:: gherkin
844857
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
847862
848863
Will raise an exception if the step is using the regular expression pattern.
849864

pytest_bdd/feature.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
1111
Syntax example:
1212
13-
Scenario: Publishing the article
14-
Given I'm an author user
15-
And I have an article
16-
When I go to the article page
17-
And I press the publish button
18-
Then I should not see the error message
19-
And the article should be published # Note: will query the database
13+
Feature: Articles
14+
Scenario: Publishing the article
15+
Given I'm an author user
16+
And I have an article
17+
When I go to the article page
18+
And I press the publish button
19+
Then I should not see the error message
20+
And the article should be published # Note: will query the database
2021
2122
:note: The "#" symbol is used for comments.
2223
:note: There're no multiline steps, the description of the step must fit in

tests/conftest.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1 @@
1-
"""Configuration for pytest runner."""
2-
3-
from pytest_bdd import when
4-
51
pytest_plugins = "pytester"
6-
7-
8-
@when("I use a when step from the parent conftest")
9-
def global_when():
10-
pass

tests/feature/outline.feature

Lines changed: 0 additions & 62 deletions
This file was deleted.

tests/feature/outline_feature.feature

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/feature/test_feature_base_dir.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ def prepare_testdir(testdir, ini_base_dir):
5454
feature_file = testdir.mkdir("features").join("steps.feature")
5555
feature_file.write(
5656
"""
57-
Scenario: When scenario found
58-
Given found
57+
Feature: Feature path
58+
Scenario: When scenario found
59+
Given found
5960
"""
6061
)
6162

0 commit comments

Comments
 (0)