SetupError should not have __context__ (causes "During handling of the above exception, another exception occurred")

Bug #1638918 reported by Free Ekanayaka
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python Fixtures
In Progress
Undecided
Free Ekanayaka

Bug Description

With Python 3, if a fixture raises an exception in its _setUp() method, the details text content rendered by testtools.content.TracebackContent will contain spurious lines about the "context" of the SetupError that
the Fixture.setUp machinery itself raises in order to wrap fixture details.

That's because Python 3 will set SetupError.__context__ to the original error raised by _setUp, and the traceback.TracebackException.format() method used by testtools.content.TracebackContent will include also the trace from the original error, although that original error was already included with addDetail and will be always printed (ending up in redundant and noisy output).

For example:

Tests running...
======================================================================
ERROR: test_foo.FooTest.test_foo
----------------------------------------------------------------------
traceback-1: {{{
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/fixtures/fixture.py", line 197, in setUp
    self._setUp()
  File "/home/ubuntu/test_foo.py", line 48, in _setUp
    raise RuntimeError("boom")
RuntimeError: boom

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/fixtures/fixture.py", line 208, in setUp
    raise SetupError(details)
fixtures.fixture.SetupError: {}
}}}

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/fixtures/fixture.py", line 197, in setUp
    self._setUp()
  File "/home/ubuntu/test_foo.py", line 48, in _setUp
    raise RuntimeError("boom")
RuntimeError: boom

To reproduce:

from fixtures import Fixture
from testtools import TestCase

class FooFixture(Fixture):

    def _setUp(self):
        raise RuntimeError("boom")

class FooTest(TestCase):

    def setUp(self):
        super(FooTest, self).setUp()
        self.useFixture(FooFixture())

    def test_foo(self):
        pass

description: updated
description: updated
Changed in python-fixtures:
assignee: nobody → Free Ekanayaka (free.ekanayaka)
status: New → In Progress
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.