Search code examples
python-behave

Python Behave is it possible to manage Steps Files in a directory system?


I have a behave Project that has grown large and I am trying to tidy it up and manage the file system.

I can group my feature files and "module" files (files that do something) in a directory structure and my tests still run. However if i try and group my steps files together under different folders within the steps folder I get a not implemented step error.

Ideally I would like to be able to lay my project out as follows

Features Component A feature file 1 feature file 2 Component B feature file 3 feature file 4

Steps Common Given Steps Common When Steps Common Then Steps Component A Given Steps When Steps Then Steps Component B Given Steps When Steps Then Steps

Currently however if I lay the steps folder out like this the component A and B steps cannot be found.

Is it possible to do this in Py Behave or do I need to just leave my steps folder and only tidy up the other directories?


Solution

  • By default behave will ONLY look for step definitions in the root feature/steps directory - if you put your files in sub-directories then behave will not recognize them.

    See also: https://github.com/behave/behave/issues/169

    In my opinion this is a needless limitation of the framework, but sadly, that is how it works and it is working as expected - even if, arguably, it would be better off working differently.

    You can get around this issue by organizing your step definitions into sub-directories and also importing those sub-directories in from a module that's loaded directly underneath feature/steps. See: https://github.com/behave/behave/blob/master/features/step.use_step_library.feature

    Not my favorite workaround, but, it is a workaround.