import unittest
class A(unittest.TestCase):
_result = {}
def test_001(self):
self.x = 1
if self.x >= 0:
self._result['test_001'] = 'pass'
@unittest.skipIf(_result['test_001'] == 'pass', '跳过')
def test_002(self):
pass
if __name__ == 'main':
unittest.main()
实际上字典中没有 ['test_001'导致报错:
C:\Users\Administrator\AppData\Local\Programs\Python\Python36\python.exe C:/Users/Administrator/PycharmProjects/Appium_auto_test/test.py
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/Appium_auto_test/test.py", line 2, in <module>
class A(unittest.TestCase):
File "C:/Users/Administrator/PycharmProjects/Appium_auto_test/test.py", line 11, in A
@unittest.skipIf(_result['test_001'] == 'pass', '跳过')
KeyError: 'test_001'
那么@unittest.skIf() 如何实现对业务逻辑判断呢?