简体   繁体   English

多个python Behave环境安装文件

[英]Multiple python Behave environment Setup files

I'm trying to break away from some standards in the behave framework and running into some issues. 我试图摆脱行为框架中的某些标准并遇到一些问题。 Is it possible to have multiple environment.py files that have the before* and after* hooks? 是否可以拥有多个具有before *和after *钩子的environment.py文件?

I'm writing a test harness for a suite of microservices. 我正在为一套微服务编写测试工具。 I have the following directory tree. 我有以下目录树。

root
|-- step_defintions
|   |-- service1
|       |-- environment.py
|       |-- __init__.py (steps, imports root.step_defintions.service1.envrionment)
|   |-- service2
|       |-- environment.py
|       |-- __init__.py (steps, imports root.step_defintions.service2.envrionment)
|-- features
|   |-- environment.py
|   |-- steps
|       |-- __init__.py (imports root.step_definitions *)
|   |-- service1
|       |-- 000_service1.feature
|       |-- 001_service1.feature
|   |-- service2
|       |-- 000_service2.feature

My problem is that it doesnt seem to pick up my before*, after* hooks in the step_definitions/service[1|2]/envrionment.py files. 我的问题是它似乎没有在step_definitions / service [1 | 2] /envrionment.py文件中的* hook之后获取我之前的*。

I'd like to have these seperate rather than in the features dir for organization purposes. 我想将这些分开而不是在功能目录中用于组织目的。 The files setup some objects and attach them to the context to track data between some steps 文件设置一些对象并将它们附加到上下文以跟踪某些步骤之间的数据

Only 2 years late, but here's my take... 只有2年的晚了,但这是我的看法......

Behave doesn't allow for a whole of flexibility in how your organize your files. Behave不允许您整理文件的灵活性。 See here: 看这里:

Moreover, Behave doesn't search the directory that it's run in recursively. 此外,Behave不会以递归方式搜索它运行的目录。 That is, Behave only looks through the current (or specified) directory for .feature files and only for .py files within the feature/steps/ directory--no further. 也就是说,Behave只查看.feature文件的当前(或指定)目录,并仅查找feature/steps/目录中的.py文件 - 不再进一步查看。

As far as I can tell, you can take advantage of Behave's "tag" ability to add some organization when it comes to running your tests. 据我所知,您可以利用Behave的“标记”功能在运行测试时添加一些组织。 Good naming conventions for your feature files and step implementations will also go a long way. 功能文件和步骤实现的良好命名约定也将有很长的路要走。

I haven't tried it extensively myself, but there's a thing called "behave main" which allows you to control an instance of Behave from a "main" file, similar to Java's main method. 我自己并没有广泛尝试过,但是有一个叫做“行为主”的东西,允许你从“主”文件控制一个Behave实例,类似于Java的主要方法。 Using this, hypothetically, you could run individual Behave tests one after another, each with their own environments, features, and steps. 假设您可以使用此功能,逐个运行各个行为测试,每个测试都有自己的环境,功能和步骤。

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

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