What are the advantages or difference in “assert False” and “self.assertFalse”

前端 未结 3 2082
孤街浪徒
孤街浪徒 2020-12-08 00:50

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?

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 01:31

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

    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.

提交回复
热议问题