我目前正在使用这个self.assertTrue(True)
来通过测试。我想要的是在出现特定警告时通过测试。
import warnings
class test(unittest.TestCase):
def test_1(self):
with warning.catch_warnings(record=False):
warning.simplefilter("error", category=CustomWarning)
try: function_that_raisesCustomWarning()
except CustomWarning as w: self.assertTrue(True)
最佳答案
如果没有迹象表明测试失败,测试总是会通过。只是不要做任何事情,以防万一一切正常。
关于python - 是否有与 `unittest.TestCase.fail()` 相反的方法来通过 Python 单元测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42161607/