unittest setUp fails to cleanup resources (from tearDown) if setUp fails - knockon effect looks like testresources issue as testresources does not use addCleanup

Bug #1010379 reported by Björn Tillenius
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
testresources
Triaged
Wishlist
Unassigned

Bug Description

If I inherit from ResourcedTestCase and something goes wrong in my setUp, the resources won't get cleaned up, since tearDown() won't be called. This can cause the next tests to fail, since the environment isn't cleaned (for example the db might not have been reset, thus containing unexpected data)

From IRC:

< BjornT> lifeless: no, the issue is that when something goes wrong in
          setUp(), TestCase.tearDown() doesn't get called, which makes
          all following tests fail with a db error (since it doesn't
          start with a clean db)
< lifeless> ah
< lifeless> cleanups addressed this, by running always (IIRC)
< lifeless> I'm not sure if we fixed tearDown in that matter for
            testtools.
< lifeless> we might want to do a cleanup based variant of
            resourcedtestcase

Revision history for this message
Robert Collins (lifeless) wrote : Re: [Bug 1010379] [NEW] Resources aren't cleaned up if setUp fails

For clarity, tearDown not running isn't due to anything in
testresources, its the test framework (unittest/unittest2/testtools)
doing that.

This however is obviously affecting whether resourceteardown is occuring.

Revision history for this message
Robert Collins (lifeless) wrote : Re: unittest setUp fails to cleanup resources (from tearDown) if setUp fails - knockon effect looks like testresources issue

Ok, so - this is basically no different with testresources than with any by-hand use of shared state across tests. Use of addCleanup rather than depending on tearDown running would fix it.

-> We should have the TestResources basic glue use addCleanup when possible.

summary: - Resources aren't cleaned up if setUp fails
+ unittest setUp fails to cleanup resources (from tearDown) if setUp fails
+ - knockon effect looks like testresources issue
summary: unittest setUp fails to cleanup resources (from tearDown) if setUp fails
- - knockon effect looks like testresources issue
+ - knockon effect looks like testresources issue as testresources does
+ not use addCleanup
Changed in testresources:
status: New → Triaged
importance: Undecided → Wishlist
Revision history for this message
Mariusz Jamro (mariusz-jamro) wrote :

The same happens if the test is skipped by raising SkipTest in setUp

class SkipTestCase(testresources.ResourcedTestCase):
    resources = [TEST_RESOURCE]

    def setUp(self):
        raise SkipTest("Skip")

    def test(self):
        pass

The TEST_RESOUCE will be made but won't be cleared.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.