【问题标题】:Does jython support class-level fixtures from unittest modulejython 是否支持来自 unittest 模块的类级夹具
【发布时间】:2013-05-11 10:43:21
【问题描述】:

我在 Jython 中使用 unittest。 (我正在写一些 Sikuli 测试)

我可以让setUp() 工作,但我无法让setUpClass() 运行。

有谁知道 Jython 是否支持此功能?有没有人让它工作?

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") 从不打印任何东西

我正在运行 Java 2.5.2(Release_2_5_2:7206,2011 年 3 月 2 日,23:12:06)

【问题讨论】:

    标签: jython sikuli jython-2.5


    【解决方案1】:

    setUpClass 是在 Python 2.7 和 Python 3.2 中引入的;根据您的标签“jython-2.5”,我建议尝试测试版 Jython 2.7beta 1,它“使我们达到与 2.7 版 CPython 的语言级别兼容性”

    【讨论】:

      【解决方案2】:

      是的,Jython 2.7.0 支持类级别的测试装置,例如 setUpClass() 和 tearDownClass()。我在带有 PyDev 插件的 Eclipse IDE 中将它与 Sikuli 和 Jython 2.7.0 一起使用,它工作得非常好。

      在使用 Jython 2.7 单元测试框架执行单个测试之前,只需查看实现它的超类 SikuliTest 以最大化和最小化正在运行的应用程序。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-04-08
        • 1970-01-01
        • 2011-11-10
        • 2017-07-02
        • 1970-01-01
        • 2019-07-29
        • 1970-01-01
        相关资源
        最近更新 更多