summaryrefslogtreecommitdiff
path: root/openstackclient/tests/image
diff options
context:
space:
mode:
authorTang Chen <chen.tang@easystack.cn>2016-04-15 15:46:19 +0800
committerTang Chen <chen.tang@easystack.cn>2016-04-20 11:15:17 +0800
commit09c20b2b5c53024c47da8828095ea95dc63810f6 (patch)
tree680c9bbbdfd46b5375e0eff940e7a1c37bcdc02c /openstackclient/tests/image
parent4639148b1dc059efab0d00a886e3f05f547a439f (diff)
downloadpython-openstackclient-09c20b2b5c53024c47da8828095ea95dc63810f6.tar.gz
Fix mutable default arguments in tests
Python’s default arguments are evaluated only once when the function is defined, not each time the function is called. This means that if you use a mutable default argument (like list and dict) and mutate it, you will and have mutated that object for all future calls to the function as well. More details about this wrong usage here: http://docs.python-guide.org/en/latest/writing/gotchas/#mutable-default-arguments In unit tests, most FakeXXX classes' methods take mutable arguments with default values [] or {}. We should change them to None. Change-Id: Iea833b66aa1379829511ad5c6d4432b72f3488e2 Closed-bug: #1550320
Diffstat (limited to 'openstackclient/tests/image')
-rw-r--r--openstackclient/tests/image/v2/fakes.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/openstackclient/tests/image/v2/fakes.py b/openstackclient/tests/image/v2/fakes.py
index 3555d2d4..f90d846d 100644
--- a/openstackclient/tests/image/v2/fakes.py
+++ b/openstackclient/tests/image/v2/fakes.py
@@ -181,7 +181,7 @@ class FakeImage(object):
"""
@staticmethod
- def create_one_image(attrs={}):
+ def create_one_image(attrs=None):
"""Create a fake image.
:param Dictionary attrs:
@@ -190,6 +190,8 @@ class FakeImage(object):
A FakeResource object with id, name, owner, protected,
visibility and tags attrs
"""
+ attrs = attrs or {}
+
# Set default attribute
image_info = {
'id': 'image-id' + uuid.uuid4().hex,
@@ -210,7 +212,7 @@ class FakeImage(object):
return image
@staticmethod
- def create_images(attrs={}, count=2):
+ def create_images(attrs=None, count=2):
"""Create multiple fake images.
:param Dictionary attrs: