Preserve the items order when calling ddt.data()
Several calls to ddt.data() change the lists of items into a set
to de-duplicate them. This happens, for example, when the list
constains microversions which may come from some variable.
In order to generate a consistent and predictable list of tests,
which can be compared over time (as ddt adds the index of the
test to the test name), replace the usage of set with
a new function which removes the duplicates but keeps the order.
Change-Id: I9cbd26016238c25487ac8104c1188cd2cf4f467e
diff --git a/manila_tempest_tests/utils.py b/manila_tempest_tests/utils.py
index f30c0fc..650614d 100644
--- a/manila_tempest_tests/utils.py
+++ b/manila_tempest_tests/utils.py
@@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+from collections import OrderedDict
import random
import re
@@ -27,6 +28,15 @@
EXPERIMENTAL = {'X-OpenStack-Manila-API-Experimental': 'True'}
+def deduplicate(items):
+ """De-duplicate a list of items while preserving the order.
+
+ It is useful when passing a list of items to ddt.data, in order
+ to remove duplicated elements which may be specified as constants.
+ """
+ return list(OrderedDict.fromkeys(items))
+
+
def get_microversion_as_tuple(microversion_str):
"""Transforms string-like microversion to two-value tuple of integers.