0

I'm getting error HOOK-ERROR in before_all: KeyError: 'environment' when running behave from command line

Project Structure:

features/ * all feature files go here
features/steps * all steps go here
features/environment.py

behave.ini (at the project level)

 [behave.userdata]
 environment = int

environment.py

def before_all(context):
   userdata = context.config.userdata
   print(userdata)
   print(userdata['environment'])

output

{}
HOOK-ERROR in before_all: KeyError: 'environment'

On a site note, if i run the features files using pycharm, I dont get this error and the environment printed out. Behave v1.2.6

Any help will be much appreciated

Satish
  • 1,976
  • 1
  • 15
  • 19

2 Answers2

1

I tried moving behave.ini to the features/ directory and I'm able to access userdata['environment'] when I run Behave from the features/ directory.

natn2323
  • 1,983
  • 1
  • 13
  • 30
  • 1
    Thank you, it does work when you move the behave.ini into the features folder. As per the documentation the file can reside in the current working directory, which i assumed it to be the root directory which has the features directory – Satish Apr 20 '18 at 18:07
  • I'm glad it helps. Does that answer your question/help to resolve your issue? If so, please mark this as the Selected Answer! – natn2323 Apr 20 '18 at 18:20
0

This should resolve your issue:

x = context.config.userdata.get('environment')
Michael Nelles
  • 5,426
  • 8
  • 41
  • 57