简体   繁体   中英

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 (eg development|test|production) in Cucumber?

behave-1.2.5 introduced the userdata concept.

behave -D BUILD_STAGE=develop …

Load the corresponding configuration for this stage in the before_all() hook.

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 export variable_name='another_value' ; behave

Please see more detailed on this on our short thread:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM