1

I am using unittest in Jython. (I am writing some Sikuli tests)

I am able to make setUp() work, but I am unable to get setUpClass() running.

Does anyone know if this is supported in Jython? Has anyone gotten it to work?

import unittest

class MyTestClass(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        print("setUpClass")
    @classmethod
    def tearDownClass(cls):
        print("tearDownClass")
    def test_1(self):
        print("test_1")

print("setUpClass") never prints anything

I am running Java 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06)

Nathaniel Waisbrot
  • 23,261
  • 7
  • 71
  • 99
cage
  • 403
  • 1
  • 5
  • 8

2 Answers2

2

setUpClass was introduced in Python 2.7 , and Python 3.2; Based on your tag "jython-2.5", I'd recommend trying the beta release Jython 2.7beta 1 which "brings us up to language level compatibility with the 2.7 version of CPython"

blotto
  • 3,387
  • 1
  • 19
  • 19
0

Yes, Jython 2.7.0 supports class level test fixtures like setUpClass() and tearDownClass(). I am using it with Sikuli and Jython 2.7.0 in Eclipse IDE with PyDev plugin and it is working very nicely.

Just have a look at superclass SikuliTest implementing it to maximize and minimize a running application before performing individual test using Jython 2.7 unit test framework.

import unittest
import org.sikuli.basics.SikulixForJython
from sikuli import *
import image_repo.ImageRepo
class SikuliTest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.region = Screen()
        cls.image_repo = ImageRepo() #ImageRepo is dictionary of images captured from application
        cls.region.click(cls.image_repo.get_image("Maximize running Application"))

    @classmethod
    def tearDownClass(cls):
        cls.region.click(cls.image_repo.get_image("Minimize opened Application"))

import SikuliTest
class SampleTest(SikuliTest):

     def setUp(self):
         print("Inside test method fixture - Setup")
     def tearDown(self):
         print("Inside test method fixture - Teardown")
     def test_sample(self):
         self.region.click(self.image_repo.get_image("ABC"))
Naval
  • 36
  • 5