Skip to content

Commit

Permalink
Allow filtering over all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Jun 25, 2021
1 parent cf4e39e commit 17379db
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
6 changes: 4 additions & 2 deletions test/easyconfigs/easyconfigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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__':
Expand Down
6 changes: 4 additions & 2 deletions test/easyconfigs/styletests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down
27 changes: 17 additions & 10 deletions test/easyconfigs/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

0 comments on commit 17379db

Please sign in to comment.