Comment 0 for bug 1188420

Revision history for this message
Leo Arias (elopio) wrote : useFixture hides the trace when the fixture throws an AssertionError on setUp

When an AssertionError is thrown during the fixture set up, then _count_relevant_tb_levels will return 1. Then, the traceback of the error will not be reported.

To reproduce:
Here I have two tests with wrong fixtures. One raises a ZeroDivisionError and the other one an AssertionError

import fixtures
import testtools

class WrongFixtureWithoutTrace(fixtures.Fixture):
   def setUp(self):
      super(WrongFixtureWithoutTrace, self).setUp()
      raise AssertionError('error')

class WrongFixtureWithTrace(fixtures.Fixture):
   def setUp(self):
      super(WrongFixtureWithTrace, self).setUp()
      1/0

class TestCase(testtools.TestCase):

    def test_without_trace(self):
        self.useFixture(WrongFixtureWithoutTrace())

    def test_with_trace(self):
        self.useFixture(WrongFixtureWithTrace())

When I run them, I get:

======================================================================
ERROR: test_with_trace (test.TestCase)
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/tmp/test.py", line 22, in test_with_trace
    self.useFixture(WrongFixtureWithTrace())
  File "/usr/lib/python2.7/dist-packages/testtools/testcase.py", line 579, in useFixture
    fixture.setUp()
  File "/tmp/test.py", line 13, in setUp
    1/0
ZeroDivisionError: integer division or modulo by zero

======================================================================
FAIL: test_without_trace (test.TestCase)
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/tmp/test.py", line 19, in test_without_trace
    self.useFixture(WrongFixtureWithoutTrace())
AssertionError: error

----------------------------------------------------------------------
Ran 2 tests in 5.854s

FAILED (failures=1, errors=1)

Not on the second test that there is only one line of the trace, hiding where and why the error occured.