Search code examples
pythoncucumberbddpython-behaverubypython

How to setup environment variables with behave (Python BDD framework)?


So our test environments dynamically change depending on the release that we are working on.

For example:

  • for abc release the URL for the test environment would be feature-abc.mycompany.com, for xyz release the URL for the test environment would be feature-xyz.company.com and so on so forth.
  • Same thing would be for staging: release-abc.mycompany.com, release-xyz.mycompany.com, etc..
  • Production is just static URL: platform.mycompany.com

With this being said, I need to specify on which URL I would like my tests to be executed using behave BDD framework for Python.

To be specific Im looking for the equivalent functionality that cucumber has for Ruby using: features/support/env.rb file to define multiple URL (qa, staging, production, etc) so that on the command-line (terminal) I would just say xyz (having qa = feature(the release).mycompany.com

Something like: How can I test different environments (e.g. development|test|production) in Cucumber?


Solution

  • Ok, so for this there is a Pull Request (PR #243) to be able to do this in behave's github repo.

    In the meantime as a workaround they suggested me to use os.getenv('variable_name', 'default_value'), and then at the command line I would just say export variable_name='another_value' ; behave

    Please see more detailed on this on our short thread:

    https://github.com/behave/behave/issues/250