[openstack-dev] addCleanup vs. tearDown

Monty Taylor mordred at inaugust.com
Tue Oct 8 15:24:03 UTC 2013


Hey!

Got a question on IRC which seemed fair game for a quick mailing list post:

Q: I see both addCleanup and tearDown in nova's test suite - which one
should I use for new code?

A: addCleanup

All new code should 100% of the time use addCleanup and not tearDown -
this is because addCleanups are all guaranteed to run, even if one of
them fails, whereas a failure inside of a tearDown can leave the rest of
the tearDown un-executed, which can leave stale state laying around.

Eventually, as we get to it, tearDown should be 100% erradicated from
OpenStack. However, we don't really need more patch churn, so I
recommend only working on it as you happen to be in related code.

Thanks!
Monty



More information about the OpenStack-dev mailing list