Python tests.test_classes() Examples
The following are 5
code examples of tests.test_classes().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tests
, or try the search function
.
Example #1
Source File: tests.py From oscrypto with MIT License | 4 votes |
def run(matcher=None, repeat=1, ci=False): """ Runs the tests :param matcher: A unicode string containing a regular expression to use to filter test names by. A value of None will cause no filtering. :param repeat: An integer - the number of times to run the tests :param ci: A bool, indicating if the tests are being run as part of CI :return: A bool - if the tests succeeded """ _preload(requires_oscrypto, not ci) warnings.filterwarnings("error") loader = unittest.TestLoader() # We have to manually track the list of applicable tests because for # some reason with Python 3.4 on Windows, the tests in a suite are replaced # with None after being executed. This breaks the repeat functionality. test_list = [] for test_class in test_classes(): if matcher: names = loader.getTestCaseNames(test_class) for name in names: if re.search(matcher, name): test_list.append(test_class(name)) else: test_list.append(loader.loadTestsFromTestCase(test_class)) stream = sys.stdout verbosity = 1 if matcher and repeat == 1: verbosity = 2 elif repeat > 1: stream = StringIO() for _ in range(0, repeat): suite = unittest.TestSuite() for test in test_list: suite.addTest(test) result = unittest.TextTestRunner(stream=stream, verbosity=verbosity).run(suite) if len(result.errors) > 0 or len(result.failures) > 0: if repeat > 1: print(stream.getvalue()) return False if repeat > 1: stream.truncate(0) return True
Example #2
Source File: tests.py From ocspbuilder with MIT License | 4 votes |
def run(matcher=None, repeat=1, ci=False): """ Runs the tests :param matcher: A unicode string containing a regular expression to use to filter test names by. A value of None will cause no filtering. :param repeat: An integer - the number of times to run the tests :param ci: A bool, indicating if the tests are being run as part of CI :return: A bool - if the tests succeeded """ _preload(requires_oscrypto, not ci) warnings.filterwarnings("error") loader = unittest.TestLoader() # We have to manually track the list of applicable tests because for # some reason with Python 3.4 on Windows, the tests in a suite are replaced # with None after being executed. This breaks the repeat functionality. test_list = [] for test_class in test_classes(): if matcher: names = loader.getTestCaseNames(test_class) for name in names: if re.search(matcher, name): test_list.append(test_class(name)) else: test_list.append(loader.loadTestsFromTestCase(test_class)) stream = sys.stdout verbosity = 1 if matcher and repeat == 1: verbosity = 2 elif repeat > 1: stream = StringIO() for _ in range(0, repeat): suite = unittest.TestSuite() for test in test_list: suite.addTest(test) result = unittest.TextTestRunner(stream=stream, verbosity=verbosity).run(suite) if len(result.errors) > 0 or len(result.failures) > 0: if repeat > 1: print(stream.getvalue()) return False if repeat > 1: stream.truncate(0) return True
Example #3
Source File: tests.py From certvalidator with MIT License | 4 votes |
def run(matcher=None, repeat=1, ci=False): """ Runs the tests :param matcher: A unicode string containing a regular expression to use to filter test names by. A value of None will cause no filtering. :param repeat: An integer - the number of times to run the tests :param ci: A bool, indicating if the tests are being run as part of CI :return: A bool - if the tests succeeded """ _preload(requires_oscrypto, not ci) warnings.filterwarnings("error") loader = unittest.TestLoader() # We have to manually track the list of applicable tests because for # some reason with Python 3.4 on Windows, the tests in a suite are replaced # with None after being executed. This breaks the repeat functionality. test_list = [] for test_class in test_classes(): if matcher: names = loader.getTestCaseNames(test_class) for name in names: if re.search(matcher, name): test_list.append(test_class(name)) else: test_list.append(loader.loadTestsFromTestCase(test_class)) stream = sys.stdout verbosity = 1 if matcher and repeat == 1: verbosity = 2 elif repeat > 1: stream = StringIO() for _ in range(0, repeat): suite = unittest.TestSuite() for test in test_list: suite.addTest(test) result = unittest.TextTestRunner(stream=stream, verbosity=verbosity).run(suite) if len(result.errors) > 0 or len(result.failures) > 0: if repeat > 1: print(stream.getvalue()) return False if repeat > 1: stream.truncate(0) return True
Example #4
Source File: tests.py From certbuilder with MIT License | 4 votes |
def run(matcher=None, repeat=1, ci=False): """ Runs the tests :param matcher: A unicode string containing a regular expression to use to filter test names by. A value of None will cause no filtering. :param repeat: An integer - the number of times to run the tests :param ci: A bool, indicating if the tests are being run as part of CI :return: A bool - if the tests succeeded """ _preload(requires_oscrypto, not ci) warnings.filterwarnings("error") loader = unittest.TestLoader() # We have to manually track the list of applicable tests because for # some reason with Python 3.4 on Windows, the tests in a suite are replaced # with None after being executed. This breaks the repeat functionality. test_list = [] for test_class in test_classes(): if matcher: names = loader.getTestCaseNames(test_class) for name in names: if re.search(matcher, name): test_list.append(test_class(name)) else: test_list.append(loader.loadTestsFromTestCase(test_class)) stream = sys.stdout verbosity = 1 if matcher and repeat == 1: verbosity = 2 elif repeat > 1: stream = StringIO() for _ in range(0, repeat): suite = unittest.TestSuite() for test in test_list: suite.addTest(test) result = unittest.TextTestRunner(stream=stream, verbosity=verbosity).run(suite) if len(result.errors) > 0 or len(result.failures) > 0: if repeat > 1: print(stream.getvalue()) return False if repeat > 1: stream.truncate(0) return True
Example #5
Source File: tests.py From asn1crypto with MIT License | 4 votes |
def run(matcher=None, repeat=1, ci=False): """ Runs the tests :param matcher: A unicode string containing a regular expression to use to filter test names by. A value of None will cause no filtering. :param repeat: An integer - the number of times to run the tests :param ci: A bool, indicating if the tests are being run as part of CI :return: A bool - if the tests succeeded """ _preload(requires_oscrypto, not ci) warnings.filterwarnings("error") loader = unittest.TestLoader() # We have to manually track the list of applicable tests because for # some reason with Python 3.4 on Windows, the tests in a suite are replaced # with None after being executed. This breaks the repeat functionality. test_list = [] for test_class in test_classes(): if matcher: names = loader.getTestCaseNames(test_class) for name in names: if re.search(matcher, name): test_list.append(test_class(name)) else: test_list.append(loader.loadTestsFromTestCase(test_class)) stream = sys.stdout verbosity = 1 if matcher and repeat == 1: verbosity = 2 elif repeat > 1: stream = StringIO() for _ in range(0, repeat): suite = unittest.TestSuite() for test in test_list: suite.addTest(test) result = unittest.TextTestRunner(stream=stream, verbosity=verbosity).run(suite) if len(result.errors) > 0 or len(result.failures) > 0: if repeat > 1: print(stream.getvalue()) return False if repeat > 1: stream.truncate(0) return True