You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.rst
+46-22Lines changed: 46 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1002,28 +1002,34 @@ then
1002
1002
Feature file paths
1003
1003
------------------
1004
1004
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.
1009
1007
1010
-
test_publish_article.py:
1008
+
.. code-block:: ini
1011
1009
1012
-
.. code-block:: python
1010
+
[pytest]
1011
+
bdd_features_base_dir = features/
1013
1012
1014
-
import pytest
1015
-
from pytest_bdd import scenario
1013
+
tests/test_publish_article.py:
1016
1014
1015
+
.. code-block:: python
1017
1016
1018
-
@pytest.fixture
1019
-
defpytestbdd_feature_base_dir():
1020
-
return'/home/user/projects/foo.bar/features'
1017
+
from pytest_bdd import scenario
1021
1018
1019
+
@scenario('foo.feature', 'Foo feature in features/foo.feature')
1020
+
deftest_foo():
1021
+
pass
1022
1022
1023
-
@scenario('publish_article.feature', 'Publishing the article')
1024
-
deftest_publish():
1023
+
@scenario(
1024
+
'foo.feature',
1025
+
'Foo feature in tests/local-features/foo.feature',
1026
+
features_base_dir='./local-features/',
1027
+
)
1028
+
deftest_foo_local():
1025
1029
pass
1026
1030
1031
+
The `features_base_dir` parameter can also be passed to the `@scenario` decorator.
1032
+
1027
1033
1028
1034
Avoid retyping the feature file name
1029
1035
------------------------------------
@@ -1065,22 +1071,15 @@ Relax strict Gherkin language validation
1065
1071
1066
1072
If your scenarios are not written in `proper` Gherkin language, e.g. they are more like textual scripts, then
1067
1073
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:
1069
1075
1070
1076
test_publish_article.py:
1071
1077
1072
1078
.. code-block:: python
1073
1079
1074
-
import pytest
1075
1080
from pytest_bdd import scenario
1076
1081
1077
-
1078
-
@pytest.fixture
1079
-
defpytestbdd_strict_gherkin():
1080
-
returnFalse
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)
1084
1083
deftest_publish():
1085
1084
pass
1086
1085
@@ -1216,6 +1215,31 @@ The output will be like:
1216
1215
As as side effect, the tool will validate the files for format errors, also some of the logic bugs, for example the
1217
1216
ordering of the types of the steps.
1218
1217
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.
0 commit comments