【问题标题】:Py.test skip messages don't show in jenkinsPy.test 跳过消息不显示在詹金斯
【发布时间】:2013-09-22 22:05:36
【问题描述】:

我在使用 py.test 进行单元测试时遇到了一个小问题。

我使用 py.test 运行我的测试并输出测试的 junitxml 报告。 这个 xml 报告被导入到 jenkins 中并生成了很好的统计数据。

当我使用派生自 unittest.TestCase 的测试类时, 我跳过预期的失败使用:

@unittest.skip("Bug 1234 : 这不起作用")

选择此测试时,此消息也会显示在 jenkins 中。

当我不使用 unittest.TestCase 类时,例如使用 py.test 参数化功能, 我跳过预期的失败使用:

@pytest.mark.xfail(reason="Bug 1234 : This doesn't work", run=False)

但是然后这个原因在jenkins中实际上并没有显示出来,而是会说:

跳过消息

预期的测试失败

我该如何解决这个问题?

【问题讨论】:

    标签: python unit-testing jenkins pytest


    【解决方案1】:

    我用这一行作为测试的第一行解决了它:

    pytest.skip("错误 1234:这不起作用")

    我宁愿使用 pytest 装饰器之一,但这样就可以了。

    【讨论】:

      【解决方案2】:

      我遇到了类似的问题,只是我收到了不同的 Jenkins 消息并且无法确定跳过了哪个测试。

      事实证明,如果模块中唯一的测试是跳过的测试,那么 jenkins 不会在测试结果列表中显示该测试(使用装饰器或 jr-be 的独奏)。您可以看到总结果中有一个跳过的测试,但无法确定跳过的测试在哪个测试或哪个模块中。

      为了解决这个问题(ok hack solve),我又在我的测试中使用装饰器并添加了一个虚拟测试(所以有 1 个运行的测试和 1 个被跳过的测试):

      @pytest.skip('SONIC-3218')
      def test_segments_create_delete(self, api):
          logging.info('TestCreateDeleteSegments.test_segments_create_delete')
      
      def test_dummy(self, api):
          '''
          Dummy test to see if suite will display in jenkins if one
          test is run and 1 is skipped (instead of having only skipped tests)
          '''
          logging.info('TestCreateDeleteSegments.test_dummy')
      

      对我来说这很有效,因为我宁愿多做 1 个虚拟测试,并且能够找到我跳过的测试。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-16
        • 1970-01-01
        • 1970-01-01
        • 2018-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多