yahoo-eng-team team mailing list archive
-
yahoo-eng-team team
-
Mailing list archive
-
Message #12833
[Bug 1295887] Re: unit test contextmanager: trying to delete resource hides original errors
** Changed in: neutron
Status: Fix Committed => Fix Released
--
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to neutron.
https://bugs.launchpad.net/bugs/1295887
Title:
unit test contextmanager: trying to delete resource hides original
errors
Status in OpenStack Neutron (virtual network service):
Fix Released
Bug description:
In unit tests, resource contextmanagers such as network(), subnet()
try to delete themselves after returning from yield even if an
exception occurs. However when an exception occurs, there is a case
where deletion fails. In this case original exception will be hidden
and it makes difficult to debug test failures.
Before each time starts, resources like database entries will be
recreated, so there is no need to try to delete resources even when an
exception occurs.
For example, there is a test with programming error below:
def test_create_dummy(self):
with self.network() as network:
port_res = self._create_port(self.fmt, network['network']['id'])
port = self.deserialize(self.fmt, port_res)
# --> Some programming error!!!!
self.assertEqual(20, hoge)
self._delete('ports', port['port']['id'])
When running this unit tests, we will get the following error. It is
hard to understand.
Traceback (most recent call last):
File "neutron/tests/unit/test_db_plugin.py", line 816, in test_create_dummy
self._delete('ports', port['port']['id'])
File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__
self.gen.throw(type, value, traceback)
File "neutron/tests/unit/test_db_plugin.py", line 534, in network
self._delete('networks', network['network']['id'])
File "neutron/tests/unit/test_db_plugin.py", line 450, in _delete
self.assertEqual(res.status_int, expected_code)
File "/home/ubuntu/neutron/.tox/py27/local/lib/python2.7/site-packages/testtools/testcase.py", line 321, in assertEqual
self.assertThat(observed, matcher, message)
File "/home/ubuntu/neutron/.tox/py27/local/lib/python2.7/site-packages/testtools/testcase.py", line 406, in assertThat
raise mismatch_error
MismatchError: 409 != 204
It is better we have the original exception:
Traceback (most recent call last):
File "neutron/tests/unit/test_db_plugin.py", line 809, in test_create_dummy
self.assertEqual(20, hoge)
NameError: global name 'hoge' is not defined
To manage notifications about this bug go to:
https://bugs.launchpad.net/neutron/+bug/1295887/+subscriptions
References