How to link Feature File to multiple step defintion files in Python BDD

1.7k Views Asked by At

I am developing a framework for automation using pytest-bdd based framework. Based on functionality I have multiple feature files and multiple step defintion files. Some scenarios take steps from other step definition files.
For example I have a Login Module , User Details Module. Now for validation of a step in User Module I do have to start with steps from the Login Module.
However in python bdd, I could see a one to one mapping of feature and step definition file. Please let me know if this a limitation of pytest bdd framework .
2

There are 2 best solutions below

0
On BEST ANSWER

Yes as far as i have worked with pytest bdd, you can only map one step definition to a single feature file, but there are work arounds to these.

1.Use conftest to keep all your common steps that you want to call across multiple feature files. 2.Use methods to be called into other step definitions by importing those methods into other step definitions.

3
On
  • I have a similar experience and i realized that if i don't use 1:1 mapping of feature to step definition file then it results in step_def not found errors e.g.pytest_bdd.exceptions.StepDefinitionNotFoundError: Step definition is not found:
  • So, I stick with the safe approach of 1:1 mapping
  • Would like to hear more thoughts feedback on this