import unittest import tests def get_cases(suite): ''' Get a list of TestCase from a TestSuite ''' if hasattr(suite, '__iter__'): res = set() for x in suite: res |= get_cases(x) return res mod = type(suite).__module__ cls = type(suite).__name__ return {f'{mod}.{cls}'} class GrayTestProgram(unittest.TestProgram): def _initArgParsers(self): # add custom CLI arguments super()._initArgParsers() p = self._main_parser p.add_argument('--keep-failed', action='store_true', help='whether to keep output files of failed tests') p.add_argument('--visual', action='store_true', help='whether to show plots, helps with debugging') p.add_argument('--update', action='store_true', help='update the reference results with the' 'current ones') p.add_argument('--binary', type=str, default='build/bin/gray', help='the gray binary to be tested') p.add_argument('--list-cases', action='store_true', help='only list the test cases') def parseArgs(self, argv): super().parseArgs(argv) # store args in the test classes tests.GrayTest.options = self tests.TestCase.options = self # handle custom harguments if self.list_cases: print(*sorted(get_cases(self.test)), sep='\n') exit() if __name__ == '__main__': # start the test runner GrayTestProgram(module=None)