I'm trying to break away from some standards in the behave framework and running into some issues. Is it possible to have multiple environment.py files that have the before* and after* hooks?
I'm writing a test harness for a suite of microservices. I have the following directory tree.
root
|-- step_defintions
| |-- service1
| |-- environment.py
| |-- __init__.py (steps, imports root.step_defintions.service1.envrionment)
| |-- service2
| |-- environment.py
| |-- __init__.py (steps, imports root.step_defintions.service2.envrionment)
|-- features
| |-- environment.py
| |-- steps
| |-- __init__.py (imports root.step_definitions *)
| |-- service1
| |-- 000_service1.feature
| |-- 001_service1.feature
| |-- service2
| |-- 000_service2.feature
My problem is that it doesnt seem to pick up my before*, after* hooks in the step_definitions/service[1|2]/envrionment.py files.
I'd like to have these seperate rather than in the features dir for organization purposes. The files setup some objects and attach them to the context to track data between some steps
Only 2 years late, but here's my take...
Behave doesn't allow for a whole of flexibility in how your organize your files. See here:
Moreover, Behave doesn't search the directory that it's run in recursively. That is, Behave only looks through the current (or specified) directory for .feature
files and only for .py
files within the feature/steps/
directory--no further.
As far as I can tell, you can take advantage of Behave's "tag" ability to add some organization when it comes to running your tests. Good naming conventions for your feature files and step implementations will also go a long way.
I haven't tried it extensively myself, but there's a thing called "behave main" which allows you to control an instance of Behave from a "main" file, similar to Java's main method. Using this, hypothetically, you could run individual Behave tests one after another, each with their own environments, features, and steps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With