1

到目前为止,我只使用了一个过程的鼻子测试,一切正常。

为了确保我的 setUp 只执行一次,我使用了一个布尔变量。

def setUp(self):
  if not self.setupOk:
    selTest.setupOk = True
    # start selenium
    # do other stuff which will be needed for all other tests to be able to run

现在我想用 --processes=5 选项运行鼻子测试

如何确保 setUp(self) 仅由一个进程执行(而其他进程正在等待)。

我试过和

def setUp(self):
  lock = multiprocessing.Lock()
  lock.acquire()
      if not self.setupOk:
        selTest.setupOk = True
        # start selenium
        # do other stuff which will be needed for all other tests to be able to run 
  lock.release()

但这似乎不起作用。

4

1 回答 1

1

setUp 将在每次测试运行之前调用。如果你想让一个方法只执行一次,你可以使用 setUpClass:

@classmethod
def setUpClass(cls):
    print "do stuff which needs to be run once"
于 2013-08-27T17:16:43.613 回答