“assert False"和“self.assertFalse"有什么优点或区别 [英] What are the advantages or difference in “assert False” and “self.assertFalse”

查看:35
本文介绍了“assert False"和“self.assertFalse"有什么优点或区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写测试,我听到有人说要使用 self.assertFalse 而不是 断言错误.为什么会这样?有什么好处吗?

I am writing tests and I have heard some people saying to use self.assertFalse rather than assert False. Why is this and are there any advantages to be had?

推荐答案

assert False 抛出一个没有有用日志信息的异常.测试出错.

assert False throws an exception without useful logging information. The test had an error.

self.assertFalse() 抛出测试失败异常,其中包含测试失败信息,如消息和测试名称.

self.assertFalse() throws a test failure exception with test failure information like a message and a test name.

错误 - 测试甚至无法运行 - 和失败 - 测试代码工作但产生错误答案之间存在差异.

There's a difference between an error -- test could not even run -- and a failure -- test code worked but produced the wrong answer.

错误是代码的严重问题.

Errors are a serious problem with your code.

失败只是需要修复的失败.

Failures are just failures that need to be fixed.

这篇关于“assert False"和“self.assertFalse"有什么优点或区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆