Skip to content

Commit

Permalink
Revert to using subunit.run instead of nose2
Browse files Browse the repository at this point in the history
There seems to be a conflict between nose2's and neutron.test.base's handling of failed tests.  They
both have non-trivial code for intercepting assertion failures, and when test_dhcp_agent.py fails on
this line:

            # Check DHCP driver was asked to restart.
            call_driver.assert_called_with('restart', mock.ANY)

the result is that we get an exception from nose2's own code about not being able to use `join` with
an argument that is not an iterable.  Modifying the nose2 code at that point shows this:

    MODIFIED OUTPUT:
    test=<networking_calico.tests.test_dhcp_agent.TestDhcpAgent.test_mainline id=0x7fc780dd9a60>
    exctype=<class 'testtools.testresult.real._StringException'>
    value=_StringException('
    Empty attachments:
      stdout

    Traceback (most recent call last):
      File "/code/.tox/py38/lib/python3.8/site-packages/neutron/tests/base.py", line 182, in func
        return f(self, *args, **kwargs)
      File "/code/networking_calico/tests/test_dhcp_agent.py", line 137, in test_mainline
        call_driver.assert_called_with(\'restart\', mock.ANY)
      File "/code/.tox/py38/lib/python3.8/site-packages/mock/mock.py", line 932, in assert_called_with
        raise AssertionError(error_message)
    AssertionError: expected call not found.
    Expected: call_driver(\'restart\', <ANY>)
    Actual: not called.
    ')
    tb=None

It looks like nose2 expects direct access to the traceback, but neutron.test.base has already
reformatted into a string form that nose2 can't handle.

When we revert to using subunit.run, we get this useful failure output:

    FAIL: networking_calico.tests.test_dhcp_agent.TestDhcpAgent.test_mainline
    tags: worker-0
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/code/.tox/py38/lib/python3.8/site-packages/neutron/tests/base.py", line 182, in func
        return f(self, *args, **kwargs)
      File "/code/networking_calico/tests/test_dhcp_agent.py", line 137, in test_mainline
        call_driver.assert_called_with('restart', mock.ANY)
      File "/code/.tox/py38/lib/python3.8/site-packages/mock/mock.py", line 932, in assert_called_with
        raise AssertionError(error_message)
    AssertionError: expected call not found.
    Expected: call_driver('restart', <ANY>)
    Actual: not called.

Obvious question: so why did I recently switch from subunit.run to nose2?  I can't remember
precisely, but I suspect it was a situation that has now been fixed in the more correct way by
imposing all of the Ussuri release's constraints on Python packages.
  • Loading branch information
nelljerram committed Jan 17, 2023
1 parent 8f6664f commit 6202046
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 2 additions & 4 deletions networking-calico/.testr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-0} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-60} \
sh -c '\
${PYTHON:-python} -m coverage run -a -m nose2 -v -s networking_calico/tests && \
${PYTHON:-python} -m coverage run -a -m nose2 -v networking_calico.plugins.ml2.drivers.calico.test.test_election && \
${PYTHON:-python} -m coverage run -a -m nose2 -v networking_calico.plugins.ml2.drivers.calico.test.test_plugin_etcd && \
${PYTHON:-python} -m coverage run -a -m nose2 -v networking_calico.plugins.ml2.drivers.calico.test.test_compaction'
${PYTHON:-python} -m coverage run -a -m subunit.run discover -t . networking_calico/tests $LISTOPT $IDOPTION && \
${PYTHON:-python} -m coverage run -a -m subunit.run discover -t . networking_calico/plugins/ml2/drivers/calico/test $LISTOPT $IDOPTION'

test_id_option=--load-list $IDFILE
test_list_option=--list
Expand Down
2 changes: 0 additions & 2 deletions networking-calico/test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ neutron>=16,<17
neutron-lib==2.3.0
mock>=3.0.0 # BSD
pyroute2<0.6.0 # Apache v2

nose2

0 comments on commit 6202046

Please sign in to comment.