简体   繁体   English

如何使用行为(Python BDD 框架)设置环境变量?

[英]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.对于 abc 版本,测试环境的 URL 将是 feature-abc.mycompany.com,对于 xyz 版本,测试环境的 URL 将是 feature-xyz.company.com 等等。
  • Same thing would be for staging: release-abc.mycompany.com, release-xyz.mycompany.com, etc..分期也是如此:release-abc.mycompany.com、release-xyz.mycompany.com 等。
  • Production is just static URL: platform.mycompany.com生产只是静态 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.话虽如此,我需要指定我希望使用 Python 的行为 BDD 框架在哪个 URL 上执行我的测试。

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具体来说,我正在寻找黄瓜对 Ruby 具有的等效功能,使用: features/support/env.rb 文件来定义多个 URL(qa、暂存、生产等),以便在命令行(终端)上我只需要说 xyz(有 qa = 功能(发布)。mycompany.com

Something like: How can I test different environments (eg development|test|production) in Cucumber?类似于: 如何在 Cucumber 中测试不同的环境(例如开发|测试|生产)?

behave-1.2.5 introduced the userdata concept.行为 1.2.5 引入了userdata概念。

behave -D BUILD_STAGE=develop …

Load the corresponding configuration for this stage in the before_all() hook.before_all()钩子中加载此阶段的相应配置。

Ok, so for this there is a Pull Request (PR #243) to be able to do this in behave's github repo.好的,为此有一个拉取请求(PR #243)可以在行为的 github 存储库中执行此操作。

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与此同时,作为一种解决方法,他们建议我使用os.getenv('variable_name', 'default_value') ,然后在命令行中我只想说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 https://github.com/behave/behave/issues/250

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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