← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #134349]: setUp and tearDown per class not per test fixture

 

Question #134349 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/134349

RaiMan proposed the following answer:
ok, I have checked it: the solution to use the test class (self) as
global storage does not work for more than one test. this is only a
solution to give information from setUp to testXXX to tearDown.

And another thing (sorry): setUp and tearDown are camel cased!

So this is a solution that at least works, when running the test from command line with option -t.
In the IDE it only works once, since the IDE does not reset it's environment on rerun, so setUp and tearDown are not processed on rerun. There has to be some other logic added to realize, that a rerun is started.

CAUTION: Sikuli runs the tests in reverse order as you might have
already noticed. This does not matter in the standard, but might be
relevant in your case.

This is the script that works as expected (using Sikuli's Settings class
as global storage)

def setUp(self):
	print "setup entry"
	try:
		Settings.already_done += 1
		if Settings.already_done > 0: return
	except:
		Settings.already_done = 0
	print "setup processing"
	# your other code

def testA(self):
	print "testA"
	Settings.already_done += 1
	return True

def testB(self):
	print "testB"
	Settings.already_done += 1
	return True

def testC(self):
	print "testC"
	Settings.already_done += 1
	return True

def testD(self):
	print "testD"
	Settings.already_done += 1
	return True

def tearDown(self):
	print "teardown entry"
	if Settings.already_done > 1: return
	print "teardown processing"
	# your other code

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.