0

I am running behave from python like this. from behave.__main__ import main as behave_main behave_main('path/to/feature_file.feature -f json -o /path/to/logs/here ) When there feature file path is missing it fails with error
ConfigError: No steps directory in "'path/to/feature_file.feature" I want to handle this exception in python. I tried with expect ConfigError It's not capturing it.

1 Answers1

1

You've got to import the ConfigError in order to expect it.

from behave.__main__ import main as behave_main
from behave.configuration import ConfigError

try:
    behave_main('path/to/feature_file.feature -f json -o /path/to/logs/here')
except ConfigError:
    print("Caught it!")
natn2323
  • 1,983
  • 1
  • 13
  • 30
  • This did nor work @musikreck ``` >>> from behave.configuration import ConfigError >>> try: ... behave_main('{} -o /tmp/log'.format(file)) ... except ConfigError: ... print ('This was error') ... ... ConfigError: No steps directory in "/webapps/pacman/features/system_status/login.featuresearch/webapps/pacman/features/system_status/search_field.feature" 1 ``` – Tibin Geo k k May 24 '18 at 14:02
  • Looks like it solved the error regarding `ConfigError`. The new issue is because behave can't find the steps directory. Behave expects your `steps/` directory to be an immediate subdirectory in the `features/` directory, i.e. `features/steps/`, not `features/specific_feature/steps/`. Also, it expects your feature files to be within the immediate `features/` directory, i.e. `features/file.feature`, not `features/specific_feature/another_file.feature`. I know, it's not super flexible. See [description](http://behave.readthedocs.io/en/latest/gherkin.html#feature-testing-layout). – natn2323 May 25 '18 at 15:18
  • An alternative that I've suggested before, but never actually tested myself, is to create separate `features/` directories and pass them as arguments to your `behave_main()` function depending on which one(s) you want to run. For instance, you could have a `first_features/` and `second_features/`, then if you only wanted the first one, just do `behave_main('first_features/')`. However, since you wouldn't have any directory specifically named `features/`, you'd always have to pass in these custom features directories as arguments to `behave_main()`. – natn2323 May 25 '18 at 15:23