Errors in setUp can lead to misleading error messaging

Bug #1299502 reported by David Stanek
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python Fixtures
Fix Released
Low
Robert Collins

Bug Description

It is possible to create a fixture that is hard to debug by overriding Fixture.setUp and not calling it *first* in the subclass' setUp implementation. The fixture instance is not in a usable state until after the parent setUp is called so any errors that happen before that are lost.

Example code:

    class MyFixture(fixtures.Fixture):

        def setUp(self):
            # do stuff that would raise an exception
            raise Exception
            super(MyFixture, self).setUp()

Error message:

    ======================================================================
    ERROR: test_test.TheTest.test
    ----------------------------------------------------------------------
    _StringException: Traceback (most recent call last):
      File "/tmp/testit/test_test.py", line 16, in setUp
        self.useFixture(MyFixture())
      File "/usr/local/lib/python2.7/dist-packages/testtools/testcase.py", line 611, in useFixture
        gather_details(fixture.getDetails(), self.getDetails())
      File "/usr/local/lib/python2.7/dist-packages/fixtures/fixture.py", line 148, in getDetails
        result = dict(self._details)
    AttributeError: 'MyFixture' object has no attribute '_details'

I didn't see this explicitly documented so it took me a little while to find the source of my errors. I think this would either be documented or possibly have Fixture._clear_cleanups called from within Fixture.__init__. I'd be happy to provide a patch for either solution, just let me know which one is more correct.

Revision history for this message
Robert Collins (lifeless) wrote :

This is a pure documentation issue IMO - doing it in __init__ would prevent fixture reuse.

Changed in python-fixtures:
status: New → Triaged
importance: Undecided → Low
Revision history for this message
Robert Collins (lifeless) wrote :

I think we've solved this with the new _setUp method, which doesn't require super() at all.

Changed in python-fixtures:
milestone: none → next
assignee: nobody → Robert Collins (lifeless)
status: Triaged → Fix Released
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.