diff --git a/test/easyconfigs/easyconfigs.py b/test/easyconfigs/easyconfigs.py index 74de638c519..cf83fa921cc 100644 --- a/test/easyconfigs/easyconfigs.py +++ b/test/easyconfigs/easyconfigs.py @@ -1324,7 +1324,7 @@ def template_easyconfig_test(self, spec): single_tests_ok = True and prev_single_tests_ok -def suite(): +def suite(loader=None): """Return all easyblock initialisation tests.""" def make_inner_test(spec_path): def innertest(self): @@ -1351,7 +1351,9 @@ def innertest(self): setattr(EasyConfigTest, innertest.__name__, innertest) print("Found %s easyconfigs..." % cnt) - return TestLoader().loadTestsFromTestCase(EasyConfigTest) + if not loader: + loader = TestLoader() + return loader.loadTestsFromTestCase(EasyConfigTest) if __name__ == '__main__': diff --git a/test/easyconfigs/styletests.py b/test/easyconfigs/styletests.py index 5664050d22e..ec27d234b46 100644 --- a/test/easyconfigs/styletests.py +++ b/test/easyconfigs/styletests.py @@ -57,9 +57,11 @@ def test_style_conformance(self): self.assertEqual(result, 0, "Found code style errors (and/or warnings): %s" % result) -def suite(): +def suite(loader=None): """Return all style tests for easyconfigs.""" - return TestLoader().loadTestsFromTestCase(StyleTest) + if not loader: + loader = TestLoader() + return loader.loadTestsFromTestCase(StyleTest) if __name__ == '__main__': diff --git a/test/easyconfigs/suite.py b/test/easyconfigs/suite.py index 986046f2a6f..3d204108c36 100644 --- a/test/easyconfigs/suite.py +++ b/test/easyconfigs/suite.py @@ -32,9 +32,9 @@ """ import os import shutil -import sys import tempfile import unittest +from unittest import main import easybuild.tools.build_log # noqa initialize EasyBuild logging, so we can disable it import test.easyconfigs.easyconfigs as e @@ -48,15 +48,22 @@ # make sure no deprecated behaviour is triggered # os.environ['EASYBUILD_DEPRECATED'] = '10000' -os.environ['EASYBUILD_TMP_LOGDIR'] = tempfile.mkdtemp(prefix='easyconfigs_test_') -# call suite() for each module and then run them all -SUITE = unittest.TestSuite([x.suite() for x in [e, s]]) -res = unittest.TextTestRunner().run(SUITE) +class EasyConfigsTestSuite(unittest.TestSuite): + def __init__(self, loader): + # call suite() for each module and then run them all + super(EasyConfigsTestSuite, self).__init__([x.suite(loader) for x in [e, s]]) -shutil.rmtree(os.environ['EASYBUILD_TMP_LOGDIR']) -del os.environ['EASYBUILD_TMP_LOGDIR'] + def run(self, *args, **kwargs): + os.environ['EASYBUILD_TMP_LOGDIR'] = tempfile.mkdtemp(prefix='easyconfigs_test_') + super(EasyConfigsTestSuite, self).run(*args, **kwargs) + shutil.rmtree(os.environ['EASYBUILD_TMP_LOGDIR']) + del os.environ['EASYBUILD_TMP_LOGDIR'] -if not res.wasSuccessful(): - sys.stderr.write("ERROR: Not all tests were successful.\n") - sys.exit(2) + +def load_tests(loader, tests, pattern): + return EasyConfigsTestSuite(loader) + + +if __name__ == '__main__': + main()