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
======================================================================
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.
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 WrongFixtureWit houtTrace( fixtures. Fixture) : WrongFixtureWit houtTrace, self).setUp() 'error' )
def setUp(self):
super(
raise AssertionError(
class WrongFixtureWit hTrace( fixtures. Fixture) : WrongFixtureWit hTrace, self).setUp()
def setUp(self):
super(
1/0
class TestCase( testtools. TestCase) :
def test_without_ trace(self) :
self.useFixtur e(WrongFixtureW ithoutTrace( ))
def test_with_ trace(self) :
self.useFixtur e(WrongFixtureW ithTrace( ))
When I run them, I get:
======= ======= ======= ======= ======= ======= ======= ======= ======= ======= ------- ------- ------- ------- ------- ------- ------- ------- ------- useFixture( WrongFixtureWit hTrace( )) python2. 7/dist- packages/ testtools/ testcase. py", line 579, in useFixture
ERROR: test_with_trace (test.TestCase)
-------
_StringException: Traceback (most recent call last):
File "/tmp/test.py", line 22, in test_with_trace
self.
File "/usr/lib/
fixture.setUp()
File "/tmp/test.py", line 13, in setUp
1/0
ZeroDivisionError: integer division or modulo by zero
======= ======= ======= ======= ======= ======= ======= ======= ======= ======= ------- ------- ------- ------- ------- ------- ------- ------- ------- useFixture( WrongFixtureWit houtTrace( ))
FAIL: test_without_trace (test.TestCase)
-------
_StringException: Traceback (most recent call last):
File "/tmp/test.py", line 19, in test_without_trace
self.
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.