From b9c3e4182f529434ee1edae00618f971f579c353 Mon Sep 17 00:00:00 2001 From: Javier Otero Date: Wed, 24 Feb 2021 11:12:30 +0100 Subject: [PATCH 1/2] Deepcopy vars when inheriting the var space --- reframe/core/variables.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/reframe/core/variables.py b/reframe/core/variables.py index ef1fce3603..4a110358b5 100644 --- a/reframe/core/variables.py +++ b/reframe/core/variables.py @@ -17,6 +17,9 @@ class _UndefinedType: '''Custom type to flag a variable as undefined.''' __slots__ = () + def __deepcopy__(self, memo): + return self + _Undefined = _UndefinedType() @@ -116,7 +119,7 @@ def join(self, other, cls): f'parent classes of class {cls.__qualname__!r}' ) - self.vars[key] = var + self.vars[key] = copy.deepcopy(var) # Carry over the set of injected variables self._injected_vars.update(other._injected_vars) From ca9545dff9d8f68baa8b8f3dbee7f4b7973bd146 Mon Sep 17 00:00:00 2001 From: Javier Otero Date: Wed, 24 Feb 2021 11:25:08 +0100 Subject: [PATCH 2/2] Extend var deepcopy unit test --- unittests/test_variables.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/unittests/test_variables.py b/unittests/test_variables.py index 0c982bf33c..1f9a4d44e5 100644 --- a/unittests/test_variables.py +++ b/unittests/test_variables.py @@ -178,8 +178,13 @@ def __init__(self): class Bar(Base): pass + class Baz(Base): + my_var = [] + + assert Base().my_var == [1, 2] assert Foo().my_var == [1, 2, 3] assert Bar().my_var == [1, 2] + assert Baz().my_var == [] def test_variable_access():