nnja nnja - 5 months ago 30
Python Question

Modular structure for behave tests

Right now I have the following directory of test features:

Tests/
--BehaveTest1/
----BehaveTest1.feature
----steps/
------test_steps.py
--BehaveTest2/
----BehaveTest2.feature
----steps/
------test_steps.py


As the test steps for BehaveTest1 and BehaveTest2 are common, I'd like to implement a common module that could be called by both test cases when they need to. At the moment I have made a common/ directory inside the Tests/ folder and import it (inside the test_steps.py files for each test feature) by:

import sys, os
sys.path.append('../common')
import common


But I do not want to mess with the path so I was wondering if there are any better ways to do this with the structure of behave test features?

Answer

The most flexible way to do this for me was to create a folder of my classes inside my steps folder:

features/test.feature
test_steps/
test_steps/classes
test_environment.py
Comments