I am new to python. I read unittest docs. In the documentation about tearDown() method, I found following lines
"This is called even if the test method raised an exception, so the implementation in subclasses may need to be particularly careful about checking internal state."
What does this statement conveys ? Can you let me understand me with the help of some good example, where the internal statement can create havoc ?
Thanks in advance.
EDIT :
I got some answers, but they are quite simple. I need some examples, where some state is involved, like tests involving database and so on.
From the OP:
"This is called even if the test method raised an exception, so the implementation in subclasses may need to be particularly careful about checking internal state."
The first things this conveys is that you can be sure that teardown is called whatever happens in your test methods. Consequently this means that you should not have any teardown code in your test method, you should move it into the teardown method.
However, if you do have an exception in your test method, this may mean that the state of your test instance may be different on different test runs and the teardown method must take this into account, or you must structure your code so that it will always work.
An example may be that you test code involves the creation of tables in the database. If you have an exception, then maybe not all the tables are created, so teardown should make sure it doesn't try to drop non-existent tables. However, the better way might be for setup to start a transaction and teardown to rollback the transaction.
teardown method in unittest python