def test_discover_pattern(self): # check the use of a non-default file name containing test cases suite = discover_tests(self.good_dir, [], 'others.py') tests = list(list_tests(suite)) self.assertEqual(1, len(tests)) self.assertEqual('test_method_common (others.OtherTestCase)', str(tests[0]))
def test_bad_file(self): # check that discovered tests that don't compile are found properly # (they used to be ignored) bad_dir = os.path.abspath(os.path.join(self.extras, 'bad_tests')) suite = discover_tests(bad_dir, []) expected = [ 'test_method_common (tests_d.DTestCase)', ] if sys.version[0] == '3': expected.append('tests_f (unittest.loader._FailedTest)') else: # pragma: no cover expected.append('tests_f (unittest.loader.ModuleImportFailure)') expected = set(expected) tests = set([str(test) for test in list_tests(suite)]) self.assertEqual(expected, tests)
def _check_shortcuts(self, expected, labels): suite = discover_tests(self.good_dir, labels=labels) tests = list_tests(suite) self.assert_test_strings(self.good_cases, expected, tests)
def test_list_tests(self): suite = discover_tests(self.good_dir) tests = list(list_tests(suite)) self.assert_test_strings(self.good_cases, self.good_cases.keys(), tests)
def get_suite(labels=[]): return discover_tests('tests', labels)
#!/usr/bin/env python import sys from waelstow import discover_tests, list_tests where = str.strip(sys.argv[1]) if where[-1] == '/': where = where[0:-1] if len(sys.argv) == 1: labels = [] else: labels = sys.argv[2:] print('Found tests:') suite = discover_tests(where, labels) for test in list_tests(suite): print(' ', test)