Description
TestCase
class methods addClassCleanup()
and doClassCleanups()
are similar to instance methods addCleanup()
and doCleanups()
. add*Cleanup()
add a callback into a list, and do*Cleanups()
pop them from a list and call. The main difference is that the latter methods use a list stored as an instance attribute while the former use a list stored as a class attribute.
The problem is that the class attribute TestCase._class_cleanups
is shared between all TestCase
subclasses. It usually does not cause the problem, because tests in different test classes are run sequentially, but if you run a new test suite while running a test, and the outer test class use addClassCleanup()
, the callback registered for the outer test class will be called when cleaning up the inner test class. It can happen when you test unittest
itself. It really happened, and was unnoticed only because the outer class did not use addClassCleanup()
.
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status