0

I have gone through many source code of functional test cases written in python. Many of the code uses assert for testing equality, why so?

praveenraj
  • 744
  • 1
  • 8
  • 20

1 Answers1

3

In most test runners, a test failure is indicated by raising an exception - which is what the assert() function does if its argument evaluates to False.

Thus assert(1 == 0) will fail, and abort that specific test with an AssertionError exception. This is caught by the test framework, and the test is marked as having failed.

The framework/test-runner then moves on to the next test.

kdopen
  • 7,877
  • 7
  • 41
  • 50