0

我正在尝试重新组织我们的自动化测试库,鼻子似乎真的很有希望。我的问题是,将 Python 对象传递给鼻子测试的最佳策略是什么?

我们的测试组织在一个 testlib 中,其中包含一组执行不同类型请求操作的模块。像这样的东西:

testlib
\-testmoda
\-testmodb
\-testmodc

在某些情况下,测试模块(即 testmoda)只不过是 test_something()、test_something2() 函数,而在某些情况下,我们在 testmob 中有一个带有 test_anotherthing1()、test_anotherthing2() 函数的 TestModB 类。很酷的是鼻子很容易找到两者。

大多数这些测试功能都是请求工厂的东西,可以轻松地共享到我们服务器场的单个连接。因此我们做了很多test_something1(cnn)、TestModB.test_anotherthing2(cnn)等。

目前我们不使用nose,取而代之的是,我们有一个大杂烩,其中包含要执行的硬编码测试列表的本土驱动程序脚本。这些驱动程序脚本中的每一个都创建自己的连接对象。维护这些脚本和连接细节是痛苦的。

我想免费利用鼻子美丽的发现功能,传入我选择的连接对象。

提前致谢!

PS 连接对象不可腌制。:(

4

2 回答 2

0

As far as I can tell, there is no easy way to simply pass custom objects to Nose.

However, as Matt pointed out there are some viable workarounds to achieve similar results.

Basically, do this:

  1. Setup a data dictionary as a package level global
  2. Add custom objects to that dictionary
  3. Create some factory functions to return those custom objects or create new ones if they're present/suitable
  4. Refactor the existing testlib\testmod* modules to use the factory
于 2011-02-14T15:22:17.467 回答
0

您可以使用工厂创建连接,然后让函数test_something1()(不带参数)使用工厂来获取连接吗?

于 2011-02-09T04:35:39.123 回答