1

So far I've used nosetests with just one process and everything works fine.

To ensure my setUp is only executed once, I'm using a boolean var.

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

Now I would like to run nosetests with the option --processes=5

How can I ensure that setUp(self) is only execued by one process (while the other processes are waiting).

I've tried to work with

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()

but this doesn't seems to work.

1 Answer 1

1

setUp will be called before every test is run. If you want a method to execute just once, you can use setUpClass:

@classmethod
def setUpClass(cls):
    print "do stuff which needs to be run once"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.