Py.测试跳过消息在jenkins中不显示

2024-06-16 11:28:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个小问题py.测试对于我的单元测试。在

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

当我使用从unittest.TestCase, 我使用以下方法跳过预期的失败:

@unittest.skip("Bug 1234 : This does not work")

当选择这个测试时,这个消息也会出现在jenkins中。在

当我不使用unittest.TestCase类,例如使用py.测试参数化功能, 我使用以下方法跳过预期的失败:

@pytest.mark.xfail(reason="Bug 1234 : This does not work", run=False)

但这个原因实际上并没有在詹金斯中显示出来,而是会说:

Skip Message

expected test failure

我该怎么解决这个问题?在


Tags: 方法py报告notxml单元测试unittestthis
2条回答

我用这条线作为测试的第一行来解决这个问题:

pytest.skip("Bug 1234: This does not work")

我宁愿使用pytest中的一个装饰器,但这也行。在

我也遇到了类似的问题,只是我收到了不同的詹金斯信息,无法判断哪个测试被跳过了。在

结果表明,如果模块中唯一的测试是跳过的测试,那么jenkins将不会在测试结果列表中显示该测试(使用decorator或jrbe的soloution)。您可以看到在总结果中有一个被跳过的测试,但无法判断被跳过的测试在哪个测试或哪个模块中。在

为了解决这个问题(好的hack solve),我回到在测试中使用decorator并添加了一个虚拟测试(因此有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')

对我来说,这是因为我宁愿有一个额外的虚拟测试,并能够找到我跳过的测试。在

相关问题 更多 >