diff --git a/test/easyblocks/init_easyblocks.py b/test/easyblocks/init_easyblocks.py index ea569e0307..62f968edd4 100644 --- a/test/easyblocks/init_easyblocks.py +++ b/test/easyblocks/init_easyblocks.py @@ -189,6 +189,10 @@ def check_extra_options_format(extra_options): def suite(): """Return all easyblock initialisation tests.""" + def make_inner_test(easyblock, **kwargs): + def innertest(self): + template_init_test(self, easyblock, **kwargs) + return innertest # dynamically generate a separate test for each of the available easyblocks easyblocks_path = get_paths_for("easyblocks")[0] @@ -199,18 +203,16 @@ def suite(): # dynamically define new inner functions that can be added as class methods to InitTest if os.path.basename(easyblock) == 'systemcompiler.py': # use GCC as name when testing SystemCompiler easyblock - code = "def innertest(self): template_init_test(self, '%s', name='GCC', version='system')" % easyblock + innertest = make_inner_test(easyblock, name='GCC', version='system') elif os.path.basename(easyblock) == 'systemmpi.py': # use OpenMPI as name when testing SystemMPI easyblock - code = "def innertest(self): template_init_test(self, '%s', name='OpenMPI', version='system')" % easyblock + innertest = make_inner_test(easyblock, name='OpenMPI', version='system') else: - code = "def innertest(self): template_init_test(self, '%s')" % easyblock + innertest = make_inner_test(easyblock) - exec(code, globals()) - - innertest.__doc__ = "Test for initialisation of easyblock %s" % easyblock # noqa - innertest.__name__ = "test_easyblock_%s" % '_'.join(easyblock.replace('.py', '').split('/')) # noqa - setattr(InitTest, innertest.__name__, innertest) # noqa + innertest.__doc__ = "Test for initialisation of easyblock %s" % easyblock + innertest.__name__ = "test_easyblock_%s" % '_'.join(easyblock.replace('.py', '').split('/')) + setattr(InitTest, innertest.__name__, innertest) return TestLoader().loadTestsFromTestCase(InitTest)