2013-05-18 39 views
5

如何创建一个单一的设置函数我的鼻子测试用例在初始化期间只调用一次?我有一个全局配置只需要设置一次,我觉得加入以下到每个模块(甚至要求每个模块的设定功能)是有点画蛇添足:鼻子测试单次设置函数调用一次

def setUp(self): 
    Configuration.configure('some configuration settings') 

回答

6

我想通了!根据文件here提供的软件包级别设置和拆卸。我所要做的就是在包的__init__.py文件中定义setup方法。

Here,您可以看到如何使用setup函数的示例。为了使事情简单:

lines = [] 
def setup(): 
    global lines 
    lines.append('test') # here, we can trigger a build 
         # and read in a file, for example 

def test_this(): 
    assert lines[0] == 'test' 
+1

哦,请举例吗?我已经多次引用链接的文档页面。我正在使用nosetest“测试函数”(不是类)和@with_setup修饰器来设置测试。但是现在在主测试中,我正在同一个test_foobar()中运行assert_equals页面:当我将它们分解为多个test_foo1(),test_foo2()等时 –

相关问题