test_update and test_get_type_list expected order causes test failures

Bug #1711469 reported by Corey Bryant
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-glareclient
Fix Released
Undecided
Ralf Haferkamp

Bug Description

TestController.test_update patch_kwargs dicts don't appear to be guaranteed to be in the order the test expects. If the dicts aren't in the expected order, the test will fail:

======================================================================
FAIL: glareclient.tests.unit.v1.test_artifacts.TestController.test_update
glareclient.tests.unit.v1.test_artifacts.TestController.test_update
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/glareclient/tests/unit/v1/test_artifacts.py", line 59, in test_update
    '/artifacts/checked_name/test-id', **patch_kwargs)
  File "/usr/lib/python3/dist-packages/mock/mock.py", line 948, in assert_called_once_with
    return self.assert_called_with(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/mock/mock.py", line 937, in assert_called_with
    six.raise_from(AssertionError(_error_message(cause)), cause)
  File "<string>", line 2, in raise_from
AssertionError: Expected call: patch('/artifacts/checked_name/test-id', headers={'Content-Type': 'application/json-patch+json'}, json=[{'path': '/remove1', 'value': None, 'op': 'replace'}, {'path': '/remove2', 'value': None, 'op': 'replace'}, {'path': '/update2', 'value': 2, 'op': 'add'}, {'path': '/update1', 'value': 1, 'op': 'add'}])
Actual call: patch('/artifacts/checked_name/test-id', headers={'Content-Type': 'application/json-patch+json'}, json=[{'op': 'replace', 'path': '/remove1', 'value': None}, {'op': 'replace', 'path': '/remove2', 'value': None}, {'op': 'add', 'path': '/update1', 'value': 1}, {'op': 'add', 'path': '/update2', 'value': 2}])

Revision history for this message
Corey Bryant (corey.bryant) wrote :

This test also fails if the list order is different than expected:

======================================================================
FAIL: glareclient.tests.unit.v1.test_artifacts.TestController.test_get_type_list
glareclient.tests.unit.v1.test_artifacts.TestController.test_get_type_list
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/glareclient/tests/unit/v1/test_artifacts.py", line 126, in test_get_type_list
    self.assertEqual(expected_types, self.c.get_type_list())
  File "/usr/lib/python3/dist-packages/testtools/testcase.py", line 350, in assertEqual
    self.assertThat(observed, matcher, message)
  File "/usr/lib/python3/dist-packages/testtools/testcase.py", line 435, in assertThat
    raise mismatch_error
testtools.matchers._impl.MismatchError: [('a', 1), ('b', 2)] != [('b', 2), ('a', 1)]

summary: - TestController.test_update patch_kwargs random order causes test failure
+ test_update and test_get_type_list expected order causes test failures
Mike Fedosin (mfedosin)
Changed in python-glareclient:
assignee: nobody → Mike Fedosin (mfedosin)
Revision history for this message
Alfredo Moralejo (amoralej) wrote :

I'm hitting this in RDO when building packages with python 3.6.

Changed in python-glareclient:
assignee: Mike Fedosin (mfedosin) → Ralf Haferkamp (rhafer)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-glareclient (master)

Reviewed: https://review.opendev.org/587628
Committed: https://git.openstack.org/cgit/x/python-glareclient/commit/?id=b1364646f78cf9e24ca9f74a7af093d240c094c0
Submitter: Zuul
Branch: master

commit b1364646f78cf9e24ca9f74a7af093d240c094c0
Author: Corey Bryant <email address hidden>
Date: Tue Jul 31 17:10:20 2018 -0400

    python3 compatibility for failing unit tests

    Handle StopIteration for Py3.7. PEP 0479,
    https://www.python.org/dev/peps/pep-0479/, makes the following
    change: "when StopIteration is raised inside a generator, it is
    replaced it with RuntimeError". And states: "If raise StopIteration
    occurs directly in a generator, simply replace it with return."

    Also fix test cases that make assumptions about the ordering of
    **kwargs. Python, up to 3.6, doesn't preserve any ordering for those.
    And the behavior differs between various Python versions.
    For details see PEP 0468 (https://www.python.org/dev/peps/pep-0468/)

    Change-Id: I9847053534ffd47c4559d504be647be0de25b651
    Closes-Bug: #1784714
    Closes-Bug: #1711469

Changed in python-glareclient:
status: In Progress → Fix Released
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.