[PKG-Openstack-devel] Bug#802677: AttributeError: 'IntegrityError' object has no attribute '__traceback__'

Neil Williams codehelp at debian.org
Fri Nov 13 09:36:42 UTC 2015


reopen 802677
thanks

On Thu, 12 Nov 2015 22:52:17 +0100
Thomas Goirand <zigo at debian.org> wrote:

> Hi Neil,
> 
> I've kept this bug opened for a while, and tried to think about it.
> Though I see no other way but to fix your lavaserver package, as I
> don't think this is a bug in testtools, but rather an API breakage
> withe the newer version.

I don't see where or how there can be a fix in lava-server, I've since
done a lot of fixes for django1.8 support and all the tests pass again.
When I reintroduce the affected python-testtools, I get the same
traceback as before.

Traceback (most recent call last):
  File "./lava_server/manage.py", line 137, in <module>
    legacy_main()
  File "./lava_server/manage.py", line 133, in legacy_main
    execute_from_command_line(sys.argv)
  File
"/usr/lib/python2.7/dist-packages/django/core/management/__init__.py",
line 351, in execute_from_command_line utility.execute() File
"/usr/lib/python2.7/dist-packages/django/core/management/__init__.py",
line 343, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File
"/usr/lib/python2.7/dist-packages/django/core/management/commands/test.py",
line 30, in run_from_argv super(Command, self).run_from_argv(argv) File
"/usr/lib/python2.7/dist-packages/django/core/management/base.py", line
394, in run_from_argv self.execute(*args, **cmd_options) File
"/usr/lib/python2.7/dist-packages/django/core/management/commands/test.py",
line 74, in execute super(Command, self).execute(*args, **options) File
"/usr/lib/python2.7/dist-packages/django/core/management/base.py", line
445, in execute output = self.handle(*args, **options) File
"/usr/lib/python2.7/dist-packages/django/core/management/commands/test.py",
line 90, in handle failures = test_runner.run_tests(test_labels) File
"/usr/lib/python2.7/dist-packages/django/test/runner.py", line 211, in
run_tests result = self.run_suite(suite) File
"/usr/lib/python2.7/dist-packages/django/test/runner.py", line 178, in
run_suite ).run(suite) File "/usr/lib/python2.7/unittest/runner.py",
line 151, in run test(result) File
"/usr/lib/python2.7/unittest/suite.py", line 70, in __call__ return
self.run(*args, **kwds) File "/usr/lib/python2.7/unittest/suite.py",
line 108, in run test(result)
  File "/usr/lib/python2.7/dist-packages/unittest2/case.py", line 673,
in __call__ return self.run(*args, **kwds)
  File "/usr/lib/python2.7/dist-packages/testtools/testcase.py", line
606, in run return run_test.run(result)
  File "/usr/lib/python2.7/dist-packages/testtools/runtest.py", line
80, in run return self._run_one(actual_result)
  File "/usr/lib/python2.7/dist-packages/testtools/runtest.py", line
94, in _run_one return
self._run_prepared_result(ExtendedToOriginalDecorator(result)) File
"/usr/lib/python2.7/dist-packages/testtools/runtest.py", line 108, in
_run_prepared_result self._run_core() File
"/usr/lib/python2.7/dist-packages/testtools/runtest.py", line 144, in
_run_core self.case._run_test_method, self.result): File
"/usr/lib/python2.7/dist-packages/testtools/runtest.py", line 193, in
_run_user return self._got_user_exception(sys.exc_info()) File
"/usr/lib/python2.7/dist-packages/testtools/runtest.py", line 213, in
_got_user_exception self.case.onException(exc_info, tb_label=tb_label)
File "/usr/lib/python2.7/dist-packages/testtools/testcase.py", line
556, in onException self._report_traceback(exc_info, tb_label=tb_label)
File "/usr/lib/python2.7/dist-packages/testtools/testcase.py", line
592, in _report_traceback self, '__testtools_tb_locals__', False)))
File "/usr/lib/python2.7/dist-packages/testtools/content.py", line 205,
in __init__ limit=limit, capture_locals=capture_locals).format()) File
"/usr/lib/python2.7/dist-packages/traceback2/__init__.py", line 449, in
__init__ exc_value.__cause__.__traceback__, AttributeError:
'IntegrityError' object has no attribute '__traceback__'

As you can see in the traceback, there is no involvement of the
lava-server code other than to start execution.

As you have invited upstream of python-testtools to be involved, I'm
not sure why it seemed appropriate to close the bug. What testing has
been done to verify that this is not a bug in python-testtools (and if
that has been done, why invite python-testtools upstream?)

> I'd strongly suggest you, in this case, to get in touch with the
> testtools upstream, and get an advice. I've put Robert as CC, as he is
> very knowledgeable about these unit test stuff. Hopefully, he will be
> able to give a quick advice.

By changing line 556 of testcase.py:
 sed '556!d' /usr/lib/python2.7/dist-packages/testtools/testcase.py
            # self._report_traceback(exc_info, tb_label=tb_label)

to
            print exc_info

I actually get useful information about why the testcase is failing.

<class 'django.db.utils.IntegrityError'>, IntegrityError('duplicate key
value violates unique constraint "auth_user_username_key"\nDETAIL:  Key
(username)=(generic-1) already exists.\n',), <traceback object at
0x7f7c98ab51b8>

So it is self._report_traceback which is itself failing to report the
traceback.

So, yes, the lava-server code is triggering the exception but
python-testtools is actively hiding relevant information by causing an
unrelated exception - this exception then *halts* the entire test run
instead of reporting that the test failed and moving on to the next.

*That* is clearly a bug in python-testtools. Unit tests are meant to
trigger exceptions, that why self.assertRaises() exists, but the unit
test must be able to rely on the testcase code to a) return the
exception that was actually raised and b) then allow execution to
continue - either within that unit test if the raise is correct or on
to the next unit test if not.

-- 


Neil Williams
=============
http://www.linux.codehelp.co.uk/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.alioth.debian.org/pipermail/openstack-devel/attachments/20151113/b8498faa/attachment.sig>


More information about the Openstack-devel mailing list