Python – Can I put step definitions in a folder that is not “steps”?

Can I put step definitions in a folder that is not “steps”?… here is a solution to the problem.

Can I put step definitions in a folder that is not “steps”?

I’m trying to use Behave on Python.
I was wondering if there was a way to put my .py files somewhere else instead of being forced to put them all in the Steps folder. My current structure looks like this

    steps/ #all code inside here, for now

Here’s what I want to accomplish

    features/ #with all the .feature files
    login/ #with all the .py files for logging in inside a service
    models/ #with all the .py files that represents a given object
    and so on

The only BDD framework I used before Behave was Cucumber with Java, which allowed step definitions to be inserted wherever I wanted (the rest was handled by Cucumber itself).
I asked this because I want to have a lot of classes in my project in order to organize my code in a better way.


This may be a bit late, but you can do the following:

The structure is as follows:


In the steps subfolder, you can create files with implementations, and then in the (or how you want to name them) you just import them:

from tests.steps.login.<feature>_step import *
from tests.steps.main_menu.<feature>_step import *

When you run it, it should find the step file. Alternatively, you can place the file anywhere in your project, as long as you have a 1 step folder and one file in the file is where you import all the steps

Related Problems and Solutions