如果@property方法返回某些输出,如何在条件中使用skipif?

  

我需要测试xml文件在当前目录中是否存在.txt格式。   这是我的代码:

@property
    def get_random_xml_file(self):
        files = get_xml_files(self)
        if files != 'No data':
            random_file = random.choice(files)
            splitext = os.path.splitext(random_file)[0]
            return splitext
        else:
            return ''
  

如果存在的话,get_xml_files给出xml文件列表,否则列表中带有''

@pytest.mark.skipif(get_random_xml_file == '',reason="Works only if there's a plan.xml file")
def test_text_created(self):
    assert path.exists(self.get_random_xml_file + ".txt")
  

当xml文件具有.txt文件时,与上述相同:

check.py::checkXML::test_text_created PASSED 
  

并且在没有xml文件时失败,但这不会跳过:

check.py::checkXML::test_text_created FAILED                                                                                                      

=============================================================================================================== FAILURES ================================================================================================================
___________________________________________________________________________________________________ checkXML.test_text_created ____________________________________________________________________________________________________

self = <check.TestplanalyseF object at 0x7ffff282e1d0>

    @pytest.mark.skipif(get_random_xml_file == '',reason="Works only if there's a plan.xml file")
    def test_text_created(self):
>       assert path.exists(self.get_random_xml_file + ".txt")
E       AssertionError: assert False
E        +  where False = <function exists at 0x7ffff7ee0a60>(('' + '.txt'))
E        +    where <function exists at 0x7ffff7ee0a60> = path.exists
E        +    and   '' = <check.checkXML object at 0x7ffff282e1d0>.get_random_xml_file

check.py:53: AssertionError
  

在没有xml文件时,请帮助如何跳过测试。

amianmian 回答:如果@property方法返回某些输出,如何在条件中使用skipif?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3169001.html

大家都在问