Skip to content

Commit 52019a1

Browse files
thefourtheyeFishrock123
authored andcommitted
test: fix default value for additional param
In Python, the default values of parameters are evaluated only once during their declaration. So, whenever the default parameter is used the same object will be used. Since we use a list, which is a mutable object, this could lead to unexpected results. PR-URL: #2553 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 59d0373 commit 52019a1

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

test/testpy/__init__.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,19 @@
4040

4141
class SimpleTestCase(test.TestCase):
4242

43-
def __init__(self, path, file, arch, mode, context, config, additional=[]):
43+
def __init__(self, path, file, arch, mode, context, config, additional=None):
4444
super(SimpleTestCase, self).__init__(context, path, arch, mode)
4545
self.file = file
4646
self.config = config
4747
self.arch = arch
4848
self.mode = mode
4949
self.tmpdir = join(dirname(self.config.root), 'tmp')
50-
self.additional_flags = additional
50+
if additional is not None:
51+
self.additional_flags = additional
52+
else:
53+
self.additional_flags = []
54+
5155

52-
5356
def GetLabel(self):
5457
return "%s %s" % (self.mode, self.GetName())
5558

@@ -81,10 +84,13 @@ def GetSource(self):
8184

8285
class SimpleTestConfiguration(test.TestConfiguration):
8386

84-
def __init__(self, context, root, section, additional=[]):
87+
def __init__(self, context, root, section, additional=None):
8588
super(SimpleTestConfiguration, self).__init__(context, root)
8689
self.section = section
87-
self.additional_flags = additional
90+
if additional is not None:
91+
self.additional_flags = additional
92+
else:
93+
self.additional_flags = []
8894

8995
def Ls(self, path):
9096
def SelectTest(name):
@@ -110,7 +116,7 @@ def GetTestStatus(self, sections, defs):
110116
test.ReadConfigurationInto(status_file, sections, defs)
111117

112118
class ParallelTestConfiguration(SimpleTestConfiguration):
113-
def __init__(self, context, root, section, additional=[]):
119+
def __init__(self, context, root, section, additional=None):
114120
super(ParallelTestConfiguration, self).__init__(context, root, section,
115121
additional)
116122

@@ -122,8 +128,8 @@ def ListTests(self, current_path, path, arch, mode):
122128
return result
123129

124130
class AddonTestConfiguration(SimpleTestConfiguration):
125-
def __init__(self, context, root, section, additional=[]):
126-
super(AddonTestConfiguration, self).__init__(context, root, section)
131+
def __init__(self, context, root, section, additional=None):
132+
super(AddonTestConfiguration, self).__init__(context, root, section, additional)
127133

128134
def Ls(self, path):
129135
def SelectTest(name):

0 commit comments

Comments
 (0)