sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #03581
Re: [Question #162606]: Python function in sikuli test file
Question #162606 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/162606
Status: Open => Answered
RaiMan proposed the following answer:
As long as you are using the unit test feature in the IDE (or from the command line using option -t) currently only setUP, tearDown and the testxxxx def()'s are interpreted. Other def()'s lead to a name error and do not work.
The developers have on their agenda to totally revise the testing support in the IDE - cannot tell when :-(
The following hack would do what you need, with the side effect, that
your reusable def() is an additional test:
def setUp(self):
print "setup"
def test1(self):
self.testLogin(run=True)
print "test1"
return True
def testLogin(self, run=False):
if not run: return True
print "doing the login"
return True
def tearDown(self):
print "teardown"
As you already might have noticed, the test cases are run in reverse
order. So testLogin would be run first, with no effect, since the run
parameter is not used by the test runner. It simply does nothing and is
reported as a passed test.
Then test1 is processed. Since it calls testLogin with run=True, the
payload of testLogin is processed. That is what you want.
So be aware, this is a hack ;-) not a feature.
If you want to build larger professional test scenarios with many reusable parts, it is recommended to use Pythons native unittest module and run the scripts as normal scripts.
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.