sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #23826
Re: [Question #243102]: unit tests won't run after being saved when using unittest.main()
Question #243102 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/243102
Status: Open => Answered
RaiMan proposed the following answer:
if __name__ == '__main__':
# When this module is executed from the command-line, run all its tests
try: unittest.main()
except SystemExit: pass
Using these typical constructs from Python programming is for the direct use of some_script.py on the command line and for using a script as main and as imported module. This conflicts with the way, how scripts are run with Sikuli (from inside IDE or from command line using -r).
Hence it is recommended to not use this construct in Sikuli scripts.
One might see this a s compatibility bug and might be right. Ideas how
to fix it are welcome.
When running unit tests use this instead of the above "if __name__ ..."
block:
unittest.TextTestRunner(verbosity=2).run(aTestSuiteToRun)
hence in your case:
unittest.TextTestRunner(verbosity=2).run(suite())
This is the best way, since many people are using alternative test
runners(HTMLTestRunner, HTMLTestRunner with Screenshots, XMLTestRunner,
...)
In this case one should from beginning put the test case classes in
separate sikuli scripts, that are imported from a main script building
suites and running the tests.
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.