From 7fc514a992681bc6cab9636eee1d595045c60849 Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Wed, 26 Aug 2015 15:22:43 +0530 Subject: [PATCH] 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. --- test/testpy/__init__.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/test/testpy/__init__.py b/test/testpy/__init__.py index 5933f8b9b62fc3..1665a54333424d 100644 --- a/test/testpy/__init__.py +++ b/test/testpy/__init__.py @@ -40,16 +40,19 @@ class SimpleTestCase(test.TestCase): - def __init__(self, path, file, arch, mode, context, config, additional=[]): + def __init__(self, path, file, arch, mode, context, config, additional=None): super(SimpleTestCase, self).__init__(context, path, arch, mode) self.file = file self.config = config self.arch = arch self.mode = mode self.tmpdir = join(dirname(self.config.root), 'tmp') - self.additional_flags = additional + if additional is not None: + self.additional_flags = additional + else: + self.additional_flags = [] + - def GetLabel(self): return "%s %s" % (self.mode, self.GetName()) @@ -81,10 +84,13 @@ def GetSource(self): class SimpleTestConfiguration(test.TestConfiguration): - def __init__(self, context, root, section, additional=[]): + def __init__(self, context, root, section, additional=None): super(SimpleTestConfiguration, self).__init__(context, root) self.section = section - self.additional_flags = additional + if additional is not None: + self.additional_flags = additional + else: + self.additional_flags = [] def Ls(self, path): def SelectTest(name): @@ -110,7 +116,7 @@ def GetTestStatus(self, sections, defs): test.ReadConfigurationInto(status_file, sections, defs) class ParallelTestConfiguration(SimpleTestConfiguration): - def __init__(self, context, root, section, additional=[]): + def __init__(self, context, root, section, additional=None): super(ParallelTestConfiguration, self).__init__(context, root, section, additional) @@ -122,7 +128,7 @@ def ListTests(self, current_path, path, arch, mode): return result class AddonTestConfiguration(SimpleTestConfiguration): - def __init__(self, context, root, section, additional=[]): + def __init__(self, context, root, section, additional=None): super(AddonTestConfiguration, self).__init__(context, root, section) def Ls(self, path):