unit tests fail under code coverage

Bug #1079609 reported by Ilya Shakhat
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Medium
Mark McClain

Bug Description

12 unit tests fail when run with code coverage enabled. All of them located in 'test_debug_commands.py'. The stack trace is common:
ERROR: test_ping_all_with_ensure_port (test_debug_commands.TestDebugCommands)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/ishakhat/Work/quantum/.venv/local/lib/python2.7/site-packages/nose/case.py", line 133, in run
    self.runTest(result)
  File "/home/ishakhat/Work/quantum/.venv/local/lib/python2.7/site-packages/nose/case.py", line 151, in runTest
    test(result)
  File "/home/ishakhat/Work/quantum/.venv/local/lib/python2.7/site-packages/unittest2/case.py", line 398, in __call__
    return self.run(*args, **kwds)
  File "/home/ishakhat/Work/quantum/.venv/local/lib/python2.7/site-packages/unittest2/case.py", line 333, in run
    self.setUp()
  File "/home/ishakhat/Work/quantum/quantum/tests/unit/test_debug_commands.py", line 44, in setUp
    cfg.CONF(args=sys.argv, project='quantum')
  File "/home/ishakhat/Work/quantum/quantum/openstack/common/cfg.py", line 1024, in __call__
    self._cli_values, leftovers = self._parse_cli_opts(args)
  File "/home/ishakhat/Work/quantum/quantum/openstack/common/cfg.py", line 1529, in _parse_cli_opts
    values, leftovers = self._oparser.parse_args(args)
  File "/usr/lib/python2.7/optparse.py", line 1401, in parse_args
    self.error(str(err))
  File "/usr/lib/python2.7/optparse.py", line 1583, in error
    self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg))
  File "/usr/lib/python2.7/optparse.py", line 1573, in exit
    sys.exit(status)
SystemExit: 2

The issue is in the line 44 of test_debug_commands:
  cfg.CONF(args=sys.argv, project='quantum')
When run with coverage there's an additional cli parameter '--with-coverage' that causes optparse to fall with error.

The possible fix is to add parameter specification:
@@ -40,6 +41,7 @@ class TestDebugCommands(unittest.TestCase):
     def setUp(self):
         cfg.CONF.register_opts(interface.OPTS)
         cfg.CONF.register_opts(QuantumDebugAgent.OPTS)
+ cfg.CONF.register_opt(cfg.StrOpt("with-coverage"))
         cfg.CONF(args=sys.argv, project='quantum')
         cfg.CONF.set_override('use_namespaces', True)
         cfg.CONF.root_helper = 'sudo'

Tags: coverage test
Changed in quantum:
status: New → Confirmed
importance: Undecided → Medium
assignee: nobody → Mark McClain (markmcclain)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to quantum (master)

Fix proposed to branch: master
Review: https://review.openstack.org/16662

Changed in quantum:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to quantum (master)

Reviewed: https://review.openstack.org/16662
Committed: http://github.com/openstack/quantum/commit/080394ae5347d0e60475511d17550e3115890185
Submitter: Jenkins
Branch: master

commit 080394ae5347d0e60475511d17550e3115890185
Author: Mark McClain <email address hidden>
Date: Wed Nov 21 13:16:37 2012 -0500

    pass static to argv to quantum-debug config parser

    fixes bug 1079609

    The quantum-debug tests were using the test runners sys.argv instead of
    creating a known value. This fix passes a fake argv to parse.

    Change-Id: Iaae7292057b839f64e172504a55034a0d9272918

Changed in quantum:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in quantum:
milestone: none → grizzly-2
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in quantum:
milestone: grizzly-2 → 2013.1
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.