我需要测试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文件时,请帮助如何跳过测试。