hard to understand test failure if osprofiler is not available

Bug #2061284 reported by Christian Boltz
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-novaclient
New
Undecided
Unassigned

Bug Description

novaclient uses try_import to import osprofiler.profiler and osprofiler.web:

    novaclient/client.py:osprofiler_profiler = importutils.try_import("osprofiler.profiler")
    novaclient/client.py:osprofiler_web = importutils.try_import("osprofiler.web")
    novaclient/shell.py:osprofiler_profiler = importutils.try_import("osprofiler.profiler")

Unfortunately two tests in novaclient/tests/unit/test_shell.py blindly expect that osprofiler.* is loaded - and fail with a hard-to understand error if it isn't:

    Failed 2 tests - output below:
    ==============================

    novaclient.tests.unit.test_shell.ShellTest.test_osprofiler
    ----------------------------------------------------------

    Captured traceback:
    ~~~~~~~~~~~~~~~~~~~
        Traceback (most recent call last):

          File "/usr/lib/python3.11/site-packages/requests_mock/mocker.py", line 317, in inner
        return func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^

          File "/home/abuild/rpmbuild/BUILD/python-novaclient-18.6.0/novaclient/tests/unit/test_shell.py", line 665, in test_osprofiler
        self.shell('list --profile swordfish', (0, 2))

          File "/home/abuild/rpmbuild/BUILD/python-novaclient-18.6.0/novaclient/tests/unit/test_shell.py", line 397, in shell
        _shell.main(argstr.split())

          File "/home/abuild/rpmbuild/BUILD/python-novaclient-18.6.0/novaclient/shell.py", line 660, in main
        self.cs = client.Client(
                  ^^^^^^^^^^^^^^

          File "/home/abuild/rpmbuild/BUILD/python-novaclient-18.6.0/novaclient/tests/unit/test_shell.py", line 662, in client
        self.assertEqual('swordfish', kwargs['profile'])
                                      ~~~~~~^^^^^^^^^^^

        KeyError: 'profile'

    novaclient.tests.unit.test_shell.ShellTestKeystoneV3.test_osprofiler
    --------------------------------------------------------------------

    Captured traceback:
    ~~~~~~~~~~~~~~~~~~~
        Traceback (most recent call last):

          File "/usr/lib/python3.11/site-packages/requests_mock/mocker.py", line 317, in inner
        return func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^

          File "/home/abuild/rpmbuild/BUILD/python-novaclient-18.6.0/novaclient/tests/unit/test_shell.py", line 665, in test_osprofiler
        self.shell('list --profile swordfish', (0, 2))

          File "/home/abuild/rpmbuild/BUILD/python-novaclient-18.6.0/novaclient/tests/unit/test_shell.py", line 397, in shell
        _shell.main(argstr.split())

          File "/home/abuild/rpmbuild/BUILD/python-novaclient-18.6.0/novaclient/shell.py", line 660, in main
        self.cs = client.Client(
                  ^^^^^^^^^^^^^^

          File "/home/abuild/rpmbuild/BUILD/python-novaclient-18.6.0/novaclient/tests/unit/test_shell.py", line 662, in client
        self.assertEqual('swordfish', kwargs['profile'])
                                      ~~~~~~^^^^^^^^^^^

        KeyError: 'profile'

Please adjust the tests to either check if osprofiler.* is available and loaded, or at least add a check if kwargs['profile'] is set - and print a useful error message if it isn't.

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.