Is there a difference between using tearDown and setUp versus __init__ and __del__ when using the pyUnit testing framework? If so, what is it exactly and what is the preferred method of use?
Is there a difference between using tearDown and setUp versus __init__ and __del__ when
Share
setUpis called before every test, andtearDownis called after every test.__init__is called once when the class is instantiated — but since a newTestCaseinstance is created for each individual test method,__init__isalso called once per test.
You generally do not need to define
__init__or__del__when writing unittests, though you could use
__init__to define a constant used by many tests.This code shows the order in which the methods are called:
prints