Skip to content

Commit 6b492d6

Browse files
youtuxolegpidsadnyi
authored andcommitted
Update documentation
1 parent 05f06bf commit 6b492d6

File tree

1 file changed

+46
-22
lines changed

1 file changed

+46
-22
lines changed

README.rst

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,28 +1002,34 @@ then
10021002
Feature file paths
10031003
------------------
10041004

1005-
By default, pytest-bdd will use current module's path as base path for
1006-
finding feature files, but this behaviour can be changed by having
1007-
fixture named ``pytestbdd_feature_base_dir`` which should return the
1008-
new base path.
1005+
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 working directory when starting pytest.
1006+
You can also override features base path on a per-scenario basis, in order to override the path for specific tests.
10091007

1010-
test_publish_article.py:
1008+
.. code-block:: ini
10111009
1012-
.. code-block:: python
1010+
[pytest]
1011+
bdd_features_base_dir = features/
10131012
1014-
import pytest
1015-
from pytest_bdd import scenario
1013+
tests/test_publish_article.py:
10161014

1015+
.. code-block:: python
10171016
1018-
@pytest.fixture
1019-
def pytestbdd_feature_base_dir():
1020-
return '/home/user/projects/foo.bar/features'
1017+
from pytest_bdd import scenario
10211018
1019+
@scenario('foo.feature', 'Foo feature in features/foo.feature')
1020+
def test_foo():
1021+
pass
10221022
1023-
@scenario('publish_article.feature', 'Publishing the article')
1024-
def test_publish():
1023+
@scenario(
1024+
'foo.feature',
1025+
'Foo feature in tests/local-features/foo.feature',
1026+
features_base_dir='./local-features/',
1027+
)
1028+
def test_foo_local():
10251029
pass
10261030
1031+
The `features_base_dir` parameter can also be passed to the `@scenario` decorator.
1032+
10271033

10281034
Avoid retyping the feature file name
10291035
------------------------------------
@@ -1065,22 +1071,15 @@ Relax strict Gherkin language validation
10651071

10661072
If your scenarios are not written in `proper` Gherkin language, e.g. they are more like textual scripts, then
10671073
you might find it hard to use `pytest-bdd` as by default it validates the order of step types (given-when-then).
1068-
To relax that validation, just override a fixture `pytestbdd_strict_gherkin` to return `False`:
1074+
To relax that validation, just pass ``strict_gherkin=False`` to the ``scenario`` and ``scenarios`` decorators:
10691075

10701076
test_publish_article.py:
10711077

10721078
.. code-block:: python
10731079
1074-
import pytest
10751080
from pytest_bdd import scenario
10761081
1077-
1078-
@pytest.fixture
1079-
def pytestbdd_strict_gherkin():
1080-
return False
1081-
1082-
1083-
@scenario('publish_article.feature', 'Publishing the article in a weird way')
1082+
@scenario('publish_article.feature', 'Publishing the article in a weird way', strict_gherkin=False)
10841083
def test_publish():
10851084
pass
10861085
@@ -1216,6 +1215,31 @@ The output will be like:
12161215
As as side effect, the tool will validate the files for format errors, also some of the logic bugs, for example the
12171216
ordering of the types of the steps.
12181217

1218+
Migration of your tests from versions 2.x.x
1219+
------------------------------------------------
1220+
1221+
In version 3.0.0, the fixtures ``pytestbdd_feature_base_dir`` and ``pytestbdd_strict_gherkin`` have been removed. The reason for it is that those fixtures had to be evaluated at module import time, but fixtures are not meant to invoked directly.
1222+
Pytest is going to not allow calling fixtures directly in version 4.
1223+
1224+
If you used ``pytestbdd_feature_base_dir`` fixture to override the path discovery, you can instead configure it in ``pytest.ini``:
1225+
1226+
.. code-block:: ini
1227+
1228+
[pytest]
1229+
bdd_features_base_dir = features/
1230+
1231+
For more details, check the `Feature file paths`_ section.
1232+
1233+
If you used ``pytestbdd_strict_gherkin`` fixture to relax the parser, you can instead specify ``strict_gherking=False`` in the declaration of your scenarios, or change it globally in the pytest configuration file:
1234+
1235+
.. code-block:: ini
1236+
1237+
[pytest]
1238+
bdd_strict_gherkin = false
1239+
1240+
For more details, check the `Relax strict Gherkin language validation`_ section.
1241+
1242+
12191243

12201244
Migration of your tests from versions 0.x.x-1.x.x
12211245
-------------------------------------------------

0 commit comments

Comments
 (0)