Skip to content

Commit 9050417

Browse files
authored
Merge pull request #587 from kkotenko/fix/grammar
Edits to documentation
2 parents 5eba5d6 + 3c47eb9 commit 9050417

File tree

1 file changed

+51
-51
lines changed

1 file changed

+51
-51
lines changed

README.rst

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ The code will look like:
267267
Example code also shows possibility to pass argument converters which may be useful if you need to postprocess step
268268
arguments after the parser.
269269

270-
You can implement your own step parser. It's interface is quite simple. The code can looks like:
270+
You can implement your own step parser. It's interface is quite simple. The code can look like:
271271

272272
.. code-block:: python
273273
@@ -334,10 +334,10 @@ it will stay untouched. To allow this, special parameter `target_fixture` exists
334334
Then foo should be "injected foo"
335335
336336
337-
In this example existing fixture `foo` will be overridden by given step `I have injecting given` only for scenario it's
337+
In this example, the existing fixture `foo` will be overridden by given step `I have injecting given` only for the scenario it's
338338
used in.
339339

340-
Sometimes it is also useful to let `when` and `then` steps to provide a fixture as well.
340+
Sometimes it is also useful to let `when` and `then` steps provide a fixture as well.
341341
A common use case is when we have to assert the outcome of an HTTP request:
342342

343343
.. code-block:: python
@@ -396,15 +396,15 @@ But in much cleaner and powerful way:
396396
Lines
397397
Then the text should be parsed with correct indentation
398398
399-
Step is considered as multiline one, if the **next** line(s) after it's first line, is indented relatively
399+
A step is considered as a multiline one, if the **next** line(s) after it's first line is indented relatively
400400
to the first line. The step name is then simply extended by adding further lines with newlines.
401401
In the example above, the Given step name will be:
402402

403403
.. code-block:: python
404404
405405
'I have a step with:\nSome\nExtra\nLines'
406406
407-
You can of course register step using full name (including the newlines), but it seems more practical to use
407+
You can of course register a step using the full name (including the newlines), but it seems more practical to use
408408
step arguments and capture lines after first line (or some subset of them) into the argument:
409409

410410
.. code-block:: python
@@ -428,7 +428,7 @@ step arguments and capture lines after first line (or some subset of them) into
428428
Scenarios shortcut
429429
------------------
430430

431-
If you have relatively large set of feature files, it's boring to manually bind scenarios to the tests using the scenario decorator. Of course with the manual approach you get all the power to be able to additionally parametrize the test, give the test function a nice name, document it, etc, but in the majority of the cases you don't need that.
431+
If you have a relatively large set of feature files, it's boring to manually bind scenarios to the tests using the scenario decorator. Of course with the manual approach you get all the power to be able to additionally parametrize the test, give the test function a nice name, document it, etc, but in the majority of the cases you don't need that.
432432
Instead, you want to bind all the scenarios found in the ``features`` folder(s) recursively automatically, by using the ``scenarios`` helper.
433433

434434
.. code-block:: python
@@ -449,7 +449,7 @@ Note that you can pass multiple paths, and those paths can be either feature fil
449449
# pass multiple paths/files
450450
scenarios('features', 'other_features/some.feature', 'some_other_features')
451451
452-
But what if you need to manually bind certain scenario, leaving others to be automatically bound?
452+
But what if you need to manually bind a certain scenario, leaving others to be automatically bound?
453453
Just write your scenario in a "normal" way, but ensure you do it **before** the call of ``scenarios`` helper.
454454

455455

@@ -470,7 +470,7 @@ In the example above, the ``test_something`` scenario binding will be kept manua
470470
Scenario outlines
471471
-----------------
472472

473-
Scenarios can be parametrized to cover few cases. These are called `Scenario Outlines <https://cucumber.io/docs/gherkin/reference/#scenario-outline>`_ in Gherkin, and the variable templates are written using angular brackets (e.g. ``<var_name>``).
473+
Scenarios can be parametrized to cover multiple cases. These are called `Scenario Outlines <https://cucumber.io/docs/gherkin/reference/#scenario-outline>`_ in Gherkin, and the variable templates are written using angular brackets (e.g. ``<var_name>``).
474474

475475
Example:
476476

@@ -514,7 +514,7 @@ Example:
514514
Organizing your scenarios
515515
-------------------------
516516

517-
The more features and scenarios you have, the more important becomes the question about their organization.
517+
The more features and scenarios you have, the more important the question of their organization becomes.
518518
The things you can do (and that is also a recommended way):
519519

520520
* organize your feature files in the folders by semantic groups:
@@ -534,7 +534,7 @@ The things you can do (and that is also a recommended way):
534534
535535
└──login.feature
536536

537-
This looks fine, but how do you run tests only for certain feature?
537+
This looks fine, but how do you run tests only for a certain feature?
538538
As pytest-bdd uses pytest, and bdd scenarios are actually normal tests. But test files
539539
are separate from the feature files, the mapping is up to developers, so the test files structure can look
540540
completely different:
@@ -559,7 +559,7 @@ completely different:
559559
pass
560560

561561

562-
For picking up tests to run we can use
562+
For picking up tests to run we can use the
563563
`tests selection <https://pytest.org/en/7.1.x/how-to/usage.html#specifying-which-tests-to-run>`_ technique. The problem is that
564564
you have to know how your tests are organized, knowing only the feature files organization is not enough.
565565
Cucumber uses `tags <https://cucumber.io/docs/cucumber/api/#tags>`_ as a way of categorizing your features
@@ -581,8 +581,8 @@ scenario test, so we can use standard test selection:
581581
582582
pytest -m "backend and login and successful"
583583
584-
The feature and scenario markers are not different from standard pytest markers, and the ``@`` symbol is stripped out automatically to allow test selector expressions. If you want to have bdd-related tags to be distinguishable from the other test markers, use prefix like ``bdd``.
585-
Note that if you use pytest ``--strict`` option, all bdd tags mentioned in the feature files should be also in the ``markers`` setting of the ``pytest.ini`` config. Also for tags please use names which are python-compatible variable names, eg starts with a non-number, underscore alphanumeric, etc. That way you can safely use tags for tests filtering.
584+
The feature and scenario markers are not different from standard pytest markers, and the ``@`` symbol is stripped out automatically to allow test selector expressions. If you want to have bdd-related tags to be distinguishable from the other test markers, use a prefix like ``bdd``.
585+
Note that if you use pytest with the ``--strict`` option, all bdd tags mentioned in the feature files should be also in the ``markers`` setting of the ``pytest.ini`` config. Also for tags please use names which are python-compatible variable names, i.e. start with a non-number, only underscores or alphanumeric characters, etc. That way you can safely use tags for tests filtering.
586586

587587
You can customize how tags are converted to pytest marks by implementing the
588588
``pytest_bdd_apply_tag`` hook and returning ``True`` from it:
@@ -621,7 +621,7 @@ The target PyTest fixture "article" gets the return value and any other step can
621621
Given I have a beautiful article
622622
When I publish this article
623623
624-
When step is referring the article to publish it.
624+
The When step is referencing the ``article`` to publish it.
625625

626626
.. code-block:: python
627627
@@ -630,10 +630,10 @@ When step is referring the article to publish it.
630630
article.publish()
631631
632632
633-
Many other BDD toolkits operate a global context and put the side effects there.
633+
Many other BDD toolkits operate on a global context and put the side effects there.
634634
This makes it very difficult to implement the steps, because the dependencies
635-
appear only as the side-effects in the run-time and not declared in the code.
636-
The publish article step has to trust that the article is already in the context,
635+
appear only as the side-effects during run-time and not declared in the code.
636+
The "publish article" step has to trust that the article is already in the context,
637637
has to know the name of the attribute it is stored there, the type etc.
638638

639639
In pytest-bdd you just declare an argument of the step function that it depends on
@@ -673,7 +673,7 @@ This way side-effects were applied to our article and PyTest makes sure that all
673673
steps that require the "article" fixture will receive the same object. The value
674674
of the "published_article" and the "article" fixtures is the same object.
675675

676-
Fixtures are evaluated only once within the PyTest scope and their values are cached.
676+
Fixtures are evaluated **only once** within the PyTest scope and their values are cached.
677677

678678

679679
Backgrounds
@@ -705,24 +705,24 @@ features.
705705
Then I should see "Your article was published."
706706
707707
In this example, all steps from the background will be executed before all the scenario's own given
708-
steps, adding possibility to prepare some common setup for multiple scenarios in a single feature.
709-
About background best practices, please read Gherkin's
708+
steps, adding a possibility to prepare some common setup for multiple scenarios in a single feature.
709+
About best practices for Background, please read Gherkin's
710710
`Tips for using Background <https://cucumber.io/docs/gherkin/reference/#tips-for-using-background>`_.
711711

712-
.. NOTE:: There is only step "Given" should be used in "Background" section,
713-
steps "When" and "Then" are prohibited, because their purpose are
714-
related to actions and consuming outcomes, that is conflict with
715-
"Background" aim - prepare system for tests or "put the system
712+
.. NOTE:: Only "Given" steps should be used in "Background" section.
713+
Steps "When" and "Then" are prohibited, because their purposes are
714+
related to actions and consuming outcomes; that is in conflict with the
715+
aim of "Background" - to prepare the system for tests or "put the system
716716
in a known state" as "Given" does it.
717-
The statement above is applied for strict Gherkin mode, which is
717+
The statement above applies to strict Gherkin mode, which is
718718
enabled by default.
719719

720720

721721
Reusing fixtures
722722
----------------
723723

724-
Sometimes scenarios define new names for the existing fixture that can be
725-
inherited (reused). For example, if we have pytest fixture:
724+
Sometimes scenarios define new names for an existing fixture that can be
725+
inherited (reused). For example, if we have the pytest fixture:
726726

727727

728728
.. code-block:: python
@@ -738,15 +738,15 @@ Then this fixture can be reused with other names using given():
738738

739739
.. code-block:: python
740740
741-
@given('I have beautiful article')
741+
@given('I have a beautiful article')
742742
def i_have_an_article(article):
743743
"""I have an article."""
744744
745745
746746
Reusing steps
747747
-------------
748748

749-
It is possible to define some common steps in the parent conftest.py and
749+
It is possible to define some common steps in the parent ``conftest.py`` and
750750
simply expect them in the child test file.
751751

752752
.. code-block:: gherkin
@@ -781,14 +781,14 @@ simply expect them in the child test file.
781781
def test_conftest():
782782
pass
783783
784-
There are no definitions of the steps in the test file. They were
784+
There are no definitions of steps in the test file. They were
785785
collected from the parent conftest.py.
786786

787787

788788
Default steps
789789
-------------
790790

791-
Here is the list of steps that are implemented inside of the pytest-bdd:
791+
Here is the list of steps that are implemented inside pytest-bdd:
792792

793793
given
794794
* trace - enters the `pdb` debugger via `pytest.set_trace()`
@@ -801,8 +801,8 @@ then
801801
Feature file paths
802802
------------------
803803

804-
By default, pytest-bdd will use current module's path as base path for finding feature files, but this behaviour can be changed in the pytest configuration file (i.e. `pytest.ini`, `tox.ini` or `setup.cfg`) by declaring the new base path in the `bdd_features_base_dir` key. The path is interpreted as relative to the `pytest root directory <https://docs.pytest.org/en/latest/reference/customize.html#rootdir>`__.
805-
You can also override features base path on a per-scenario basis, in order to override the path for specific tests.
804+
By default, pytest-bdd will use the current module's path as the base path for finding feature files, but this behaviour can be changed in the pytest configuration file (i.e. `pytest.ini`, `tox.ini` or `setup.cfg`) by declaring the new base path in the `bdd_features_base_dir` key. The path is interpreted as relative to the `pytest root directory <https://docs.pytest.org/en/latest/reference/customize.html#rootdir>`__.
805+
You can also override the features base path on a per-scenario basis, in order to override the path for specific tests.
806806

807807
pytest.ini:
808808

@@ -869,15 +869,15 @@ in the Python docs.
869869

870870
Programmatic step generation
871871
----------------------------
872-
Sometimes you have step definitions that would be much easier to automate rather than writing manually over and over again.
872+
Sometimes you have step definitions that would be much easier to automate rather than writing them manually over and over again.
873873
This is common, for example, when using libraries like `pytest-factoryboy <https://pytest-factoryboy.readthedocs.io/>`_ that automatically creates fixtures.
874874
Writing step definitions for every model can become a tedious task.
875875

876876
For this reason, pytest-bdd provides a way to generate step definitions automatically.
877877

878878
The trick is to pass the ``stacklevel`` parameter to the ``given``, ``when``, ``then``, ``step`` decorators. This will instruct them to inject the step fixtures in the appropriate module, rather than just injecting them in the caller frame.
879879

880-
Let's look at a concrete example; let's say you have a class ``Wallet`` that has some amount for each currency:
880+
Let's look at a concrete example; let's say you have a class ``Wallet`` that has some amount of each currency:
881881

882882
.. code-block:: python
883883
@@ -1010,24 +1010,24 @@ Hooks
10101010
pytest-bdd exposes several `pytest hooks <https://docs.pytest.org/en/7.1.x/reference/reference.html#hooks>`_
10111011
which might be helpful building useful reporting, visualization, etc. on top of it:
10121012

1013-
* pytest_bdd_before_scenario(request, feature, scenario) - Called before scenario is executed
1013+
* `pytest_bdd_before_scenario(request, feature, scenario)` - Called before scenario is executed
10141014

1015-
* pytest_bdd_after_scenario(request, feature, scenario) - Called after scenario is executed
1015+
* `pytest_bdd_after_scenario(request, feature, scenario)` - Called after scenario is executed
10161016
(even if one of steps has failed)
10171017

1018-
* pytest_bdd_before_step(request, feature, scenario, step, step_func) - Called before step function
1018+
* `pytest_bdd_before_step(request, feature, scenario, step, step_func)` - Called before step function
10191019
is executed and it's arguments evaluated
10201020

1021-
* pytest_bdd_before_step_call(request, feature, scenario, step, step_func, step_func_args) - Called before step
1021+
* `pytest_bdd_before_step_call(request, feature, scenario, step, step_func, step_func_args)` - Called before step
10221022
function is executed with evaluated arguments
10231023

1024-
* pytest_bdd_after_step(request, feature, scenario, step, step_func, step_func_args) - Called after step function
1024+
* `pytest_bdd_after_step(request, feature, scenario, step, step_func, step_func_args)` - Called after step function
10251025
is successfully executed
10261026

1027-
* pytest_bdd_step_error(request, feature, scenario, step, step_func, step_func_args, exception) - Called when step
1027+
* `pytest_bdd_step_error(request, feature, scenario, step, step_func, step_func_args, exception)` - Called when step
10281028
function failed to execute
10291029

1030-
* pytest_bdd_step_func_lookup_error(request, feature, scenario, step, exception) - Called when step lookup failed
1030+
* `pytest_bdd_step_func_lookup_error(request, feature, scenario, step, exception)` - Called when step lookup failed
10311031

10321032

10331033
Browser testing
@@ -1052,7 +1052,7 @@ To have an output in json format:
10521052

10531053
pytest --cucumberjson=<path to json report>
10541054

1055-
This will output an expanded (meaning scenario outlines will be expanded to several scenarios) cucumber format.
1055+
This will output an expanded (meaning scenario outlines will be expanded to several scenarios) Cucumber format.
10561056

10571057
To enable gherkin-formatted output on terminal, use
10581058

@@ -1065,8 +1065,8 @@ Test code generation helpers
10651065
----------------------------
10661066

10671067
For newcomers it's sometimes hard to write all needed test code without being frustrated.
1068-
To simplify their life, simple code generator was implemented. It allows to create fully functional
1069-
but of course empty tests and step definitions for given a feature file.
1068+
To simplify their life, a simple code generator was implemented. It allows to create fully functional
1069+
(but of course empty) tests and step definitions for a given feature file.
10701070
It's done as a separate console script provided by pytest-bdd package:
10711071

10721072
::
@@ -1083,7 +1083,7 @@ It will print the generated code to the standard output so you can easily redire
10831083
Advanced code generation
10841084
------------------------
10851085

1086-
For more experienced users, there's smart code generation/suggestion feature. It will only generate the
1086+
For more experienced users, there's a smart code generation/suggestion feature. It will only generate the
10871087
test code which is not yet there, checking existing tests and step definitions the same way it's done during the
10881088
test execution. The code suggestion tool is called via passing additional pytest arguments:
10891089

@@ -1128,7 +1128,7 @@ Migration of your tests from versions 5.x.x
11281128
The primary focus of the pytest-bdd is the compatibility with the latest gherkin developments
11291129
e.g. multiple scenario outline example tables with tags support etc.
11301130

1131-
In order to provide the best compatibility it is best to support the features described in the official
1131+
In order to provide the best compatibility, it is best to support the features described in the official
11321132
gherkin reference. This means deprecation of some non-standard features that were implemented in pytest-bdd.
11331133

11341134

@@ -1146,7 +1146,7 @@ The example tables should have horizontal orientation.
11461146
Step arguments are no longer fixtures
11471147
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11481148
Step parsed arguments conflicted with the fixtures. Now they no longer define fixture.
1149-
If the fixture has to be defined by the step the target_fixture param should be used.
1149+
If the fixture has to be defined by the step, the target_fixture param should be used.
11501150

11511151

11521152
Variable templates in steps are only parsed for Scenario Outlines
@@ -1204,7 +1204,7 @@ Scenario `example_converters` are removed in favor of the converters provided on
12041204
12051205
Refuse combining scenario outline and pytest parametrization
12061206
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1207-
The significant downside of combining scenario outline and pytest parametrization approach was inability to see the
1207+
The significant downside of combining scenario outline and pytest parametrization approach was an inability to see the
12081208
test table from the feature file.
12091209

12101210

@@ -1214,7 +1214,7 @@ Migration of your tests from versions 3.x.x
12141214
-------------------------------------------
12151215

12161216

1217-
Given steps are no longer fixtures. In case it is needed to make given step setup a fixture
1217+
Given steps are no longer fixtures. In case it is needed to make given step setup a fixture,
12181218
the target_fixture parameter should be used.
12191219

12201220

@@ -1225,7 +1225,7 @@ the target_fixture parameter should be used.
12251225
return Article()
12261226
12271227
1228-
Given steps no longer have fixture parameter. In fact the step may depend on multiple fixtures.
1228+
Given steps no longer have the `fixture` parameter. In fact the step may depend on multiple fixtures.
12291229
Just normal step declaration with the dependency injection should be used.
12301230

12311231
.. code-block:: python

0 commit comments

Comments
 (0)