pytest-bdd
pytest-bdd copied to clipboard
pytest-bdd should be internationalized
Cucumber, Behave, and other BDD tools allow you to write your feature files in just about whatever language you want. It would be really handy to have the ability to use keywords other than the English versions.
A useful implementation would be one that allows anyone to create a new language file. Ideally it would also comes bundled with several language files for mainstream languages (i.e. French, Spanish, German, Russian, Chinese, etc.), though this is less useful than the ability to create a new custom language file.
Do you mean having possibility to translate: "Feature, Background, Scenario, Given, When, Then, And"? Can you provide some links where i can see how does it look like?
Yes. That's exactly what I mean :)
Here's the wiki for this feature from the cucumber project https://github.com/cucumber/cucumber/wiki/Translations
+1
+1
+1
the whole thing can be done just by monkeypatching those https://github.com/pytest-dev/pytest-bdd/blob/master/pytest_bdd/types.py just make sure you monkeypatch it before calling scenario function
@bubenkoff Can you show me an example?
in the __init__py of the tests folder:
from pytest_bdd import types
types.FEATURE = "italian feature" ....
Actually, patching pytest_bdd.feature.STEP_PREFIXES would be slightly better, as you don't need to alter the types, but rather the parsing. And since a few of those translations are many-to-one-type.
e.g. according to https://github.com/cucumber/cucumber/blob/master/gherkin/gherkin-languages.json#L1138
from pytest_bdd.feature import STEP_PREFIXES
from pytest_bdd import types
STEP_PREFIXES[:] = [] # clear existing translations to avoid conflicts.
STEP_PREFIXES.append(("Quand ", types.WHEN))
STEP_PREFIXES.append(("Lorsque ", types.WHEN))
STEP_PREFIXES.append(("Lorsqu'", types.WHEN))
...
I have written this in the init.py file of the tests folder and I get a NoScenariosFound exception. Any idea what I did wrong?
@MichielPeeters7 In the current implementation of pytest-bdd, you can't just overwrite the STEP_PREFIXES or types, because they are loaded when the plugin loads.
This issue is perhaps duplicated by #397