def run_test_suite(suite): test_runner = nose.core.TextTestRunner(verbosity=2) if TEST_MODE == 'ci': from teamcity.unittestpy import TeamcityTestRunner test_runner = TeamcityTestRunner() return test_runner.run(suite)
def test(teamcity, verbosity): loader = unittest.TestLoader() tests = loader.discover(TESTS_DIR, pattern='test*.py') if teamcity: runner = TeamcityTestRunner() else: runner = unittest.TextTestRunner(verbosity=verbosity) result = runner.run(tests) exit_code = 1 if result.wasSuccessful(): exit_code = 0 sys.exit(exit_code)
def _run_tests_randomly(): unittest.TestLoader.sortTestMethodsUsing = lambda _, x, y: random.choice( [-1, 1]) if is_running_under_teamcity(): runner = TeamcityTestRunner() else: runner = unittest.TextTestRunner() unittest.main(testRunner=runner)
def run_tests(path): pat, paths = "test", [] search_path_pat(path, pat, paths) for path in paths: test = unittest.TestLoader().discover(path, "test*py") if is_running_under_teamcity(): TeamcityTestRunner(verbosity=2).run(test) else: unittest.TextTestRunner(verbosity=2).run(test)
def get_test_runner(): import unittest try: from teamcity import is_running_under_teamcity from teamcity.unittestpy import TeamcityTestRunner from teamcity.unittestpy import TeamcityServiceMessages if is_running_under_teamcity(): runner = TeamcityTestRunner() else: runner = unittest.TextTestRunner() except ModuleNotFoundError: runner = unittest.TextTestRunner() return runner
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]): """ Run the unit tests for all the test labels in the provided list. Labels must be of the form: - app.TestClass.test_method Run a single specific test method - app.TestClass Run all the test methods in a given class - app Search for doctests and unittests in the named application. When looking for tests, the test runner will look in the models and tests modules for the application. A list of 'extra' tests may also be provided; these tests will be added to the test suite. Returns the number of tests that failed. """ setup_test_environment() settings.DEBUG = False suite = unittest.TestSuite() if test_labels: for label in test_labels: if '.' in label: suite.addTest(build_test(label)) else: app = get_app(label) suite.addTest(build_suite(app)) else: for app in get_apps(): suite.addTest(build_suite(app)) for test in extra_tests: suite.addTest(test) suite = reorder_suite(suite, (TestCase, )) old_name = settings.DATABASE_NAME from django.db import connection connection.creation.create_test_db(verbosity, autoclobber=not interactive) result = TeamcityTestRunner().run(suite) connection.creation.destroy_test_db(old_name, verbosity) teardown_test_environment() return len(result.failures) + len(result.errors)
def monkeypatch_teamcity_runner(): try: import unittest from teamcity import underTeamcity from teamcity.unittestpy import TeamcityTestRunner runner = TeamcityTestRunner() if underTeamcity( ) else unittest.TextTestRunner() org_main = unittest.main def monkey_patch(*args, **kwargs): kwargs['testRunner'] = runner org_main(*args, **kwargs) unittest.main = monkey_patch except ImportError: print "Missing teamcity-messages package for running tests in Teamcity." print "Refusing to even try enabling it!"
def run(suite): if is_running_under_teamcity(): runner = TeamcityTestRunner() else: runner = unittest.TextTestRunner() runner.run(suite)
continue # Import the test file and find all TestClass clases inside it. module_name = '%s.%s' % (module, filename[:-3]) # logging.critical('adding %s' % module_name) # test_suite.addTest(unittest.TestLoader().loadTestsFromName(module_name)) test_module = __import__(module_name, {}, {}, filename[:-3]) test_suite.addTest(unittest.TestLoader().loadTestsFromModule(test_module)) return test_suite except Exception: logging.critical("Error loading tests.", exc_info=1) raise SystemExit("Error loading tests.") if __name__ == "__main__": sys.path.insert(0, os.path.join(os.environ['APPENGINEDIR'], 'lib', 'django')) os.environ['SERVER_SOFTWARE'] = 'Development/unittest' # to ensure correct reloading of config/FSM import sys if len(sys.argv) > 1: # tests specified test_suite = unittest.TestLoader().loadTestsFromNames(sys.argv[1:]) else: test_suite = suite() if teamcity.underTeamcity(): TeamcityTestRunner().run(test_suite) else: unittest.TextTestRunner(verbosity=int(os.environ.get('UNITTEST_VERBOSITY', 1))).run(test_suite)
def run_suite(self, suite, **kwargs): if is_running_under_teamcity(): return TeamcityTestRunner().run(suite) else: return unittest.TextTestRunner(verbosity=self.verbosity, failfast=self.failfast).run(suite)
aae(actual_libor3_df, expected_libor3_df) aae(actual_sonia_df, expected_sonia_df) risk_engine = RiskCalculator(curve_builder, build_output) instrument_regex = "USD/.*" numpy.testing.assert_equal(len(risk_engine.find_instruments(instrument_regex)), 32) instruments_to_bump = risk_engine.find_instruments(instrument_regex) bumped_curves = risk_engine.get_bumped_curvemap(instruments_to_bump, 1e-4, BumpType.FULL_REBUILD) bumped_curves_jacobian = risk_engine.get_bumped_curvemap(instruments_to_bump, 1e-4, BumpType.JACOBIAN_REBUILD) numpy.testing.assert_equal(len(bumped_curves), len(bumped_curves_jacobian)) test_pillars = linspace(eval_date + 30, eval_date + 50 * 365, 15) for curve_name in sorted(bumped_curves.keys()): c0 = build_output.output_curvemap[curve_name] c1 = bumped_curves[curve_name] c2 = bumped_curves_jacobian[curve_name] zr0 = c0.get_zero_rate(test_pillars, CouponFreq.CONTINUOUS, DCC.ACT365) zr1 = c1.get_zero_rate(test_pillars, CouponFreq.CONTINUOUS, DCC.ACT365) zr2 = c2.get_zero_rate(test_pillars, CouponFreq.CONTINUOUS, DCC.ACT365) bumpdiff = max(abs((zr2 - zr0) / zr0)) error = max(abs((zr2 - zr1) / zr1)) self.assertLess(error, bumpdiff / 100.) if __name__ == '__main__': if is_running_under_teamcity(): runner = TeamcityTestRunner() else: runner = unittest.TextTestRunner() unittest.main(testRunner=runner)
import unittest from teamcity.unittestpy import TeamcityTestRunner class TestXXX(unittest.TestCase): def runTest(self): self.fail("Grr") TeamcityTestRunner().run(TestXXX())
# -*- coding: utf-8 -*- import unittest from teamcity import is_running_under_teamcity from teamcity.unittestpy import TeamcityTestRunner if __name__ == '__main__': all_tests = unittest.TestLoader().discover('./', pattern='test_*.py') if is_running_under_teamcity(): runner = TeamcityTestRunner() else: runner = unittest.TextTestRunner() runner.run(all_tests)
import unittest import os import sys import os.path sys.path.append(os.path.abspath("caffeine")) if __name__ == '__main__': import sys print (sys.argv) if "--teamcity" in sys.argv: from teamcity.unittestpy import TeamcityTestRunner runner = TeamcityTestRunner() elif "--sonar" in sys.argv: sys.path.append("/caffeine/unittest-xml-reporting-master/src")# work around https://github.com/danielfm/unittest-xml-reporting/pull/46 print (sys.path) import xmlrunner runner = xmlrunner.XMLTestRunner(output='/sonar-reports/') elif "test_loopback" in sys.argv: print ("Running loopback") from testMultiplatform import TestSequence TestSequence().test_loopback() else: print ("Nothing interesting in sys.argv. Running standard tests.") runner = unittest.TextTestRunner() #import pdb #pdb.set_trace() testsuite = unittest.TestLoader().discover('tests') runner.run(testsuite)
nightSuite = suites['nightly'] allSuite = suites['all'] smallSuite.addTests(KratosUnittest.TestLoader().loadTestsFromTestCases( small_test_cases)) nightSuite.addTests(KratosUnittest.TestLoader().loadTestsFromTestCases( night_test_cases)) allSuite.addTests( KratosUnittest.TestLoader().loadTestsFromTestCases(all_test_cases)) return suites if __name__ == '__main__': is_team_city = False try: from teamcity import is_running_under_teamcity from teamcity.unittestpy import TeamcityTestRunner is_team_city = is_running_under_teamcity() except ImportError: pass if is_team_city: import unittest runner = TeamcityTestRunner() runner.run(AssambleTestSuites(is_team_city)) else: KratosUnittest.runTests(AssambleTestSuites(is_team_city))
import unittest from teamcity.unittestpy import TeamcityTestRunner from teamcity import is_running_under_teamcity class TestXXX(unittest.TestCase): def runTest(self): assert 1 == 1 if __name__ == '__main__': if is_running_under_teamcity(): runner = TeamcityTestRunner() else: runner = unittest.TextTestRunner() nested_suite = unittest.TestSuite() nested_suite.addTest(TestXXX()) suite = unittest.TestSuite() suite.addTest(nested_suite) runner.run(suite)
def prepare_test_environment(): test_utils.clear_test_dir() test_utils.create_test_dir() images = test_utils.create_test_images() render_images = test_utils.create_head_images() test_utils.save_scene(filename='render.blend') DataHolder.set_image_file_names([image.filepath for image in images] + render_images) if __name__ == "__main__": logger = logging.getLogger(__name__) try: from teamcity import is_running_under_teamcity from teamcity.unittestpy import TeamcityTestRunner runner = TeamcityTestRunner() logger.info('Teamcity TeamcityTestRunner is active') except ImportError: logger.error('ImportError: Teamcity is not installed') runner = unittest.TextTestRunner() logger.error('Unittest TextTestRunner is active') except Exception: logger.error('Unhandled error with Teamcity') runner = unittest.TextTestRunner() logger.error('Unittest TextTestRunner is active') prepare_test_environment() # unittest.main() # -- Doesn't work with Blender, so we use Suite suite = unittest.defaultTestLoader.loadTestsFromTestCase(FaceBuilderTest) result = runner.run(suite)
# coding=utf-8 import sys from teamcity.unittestpy import TeamcityTestRunner from unittest import TestCase, main class SpamTest(TestCase): @classmethod def setUpClass(cls): print("1") def test_test(self): print("stdout_test1") print("stdout_test2") sys.stderr.write("stderr_") sys.stderr.write("test1") sys.stderr.flush() sys.stderr.write("stderr_test2") raise Exception("A") @classmethod def tearDownClass(cls): print("3") main(testRunner=TeamcityTestRunner(buffer=True))
Factorials of floats are OK, but the float must be an exact integer: >>> factorial(30.1) Traceback (most recent call last): ... ValueError: n must be exact integer It must also not be ridiculously large: >>> factorial(1e100) Traceback (most recent call last): ... OverflowError: n too large """ import math if not n >= 0: raise ValueError("n must be >= 0") if math.floor(n) != n: raise ValueError("n must be exact integer") if n+1 == n: # catch a value like 1e300 raise OverflowError("n too large") result = 1 factor = 2 while factor <= n: result *= factor factor += 1 return result TeamcityTestRunner().run(doctest.DocTestSuite(sys.modules[__name__]))
from simple_tests import SimpleTests from nose.loader import TestLoader from teamcity.unittestpy import TeamcityTestRunner if __name__ == '__main__': test_loader = TestLoader().loadTestsFromTestClass(SimpleTests) TeamcityTestRunner().run(test_loader)
import unittest from teamcity import is_running_under_teamcity from teamcity.unittestpy import TeamcityTestRunner if __name__ == "__main__": all_tests = unittest.TestLoader().discover(start_dir='githubcommit', pattern='*_test.py') if is_running_under_teamcity(): TeamcityTestRunner().run(all_tests) else: unittest.TextTestRunner().run(all_tests)
def run_suite(self, suite, **kwargs): return TeamcityTestRunner().run(suite)
__author__ = 'broken' from teamcity.unittestpy import TeamcityTestRunner import unittest from gaetestbed import DataStoreTestCase from Pac.DataFactory.dbUser import User from Pac import Setup class TestSetup(DataStoreTestCase, unittest.TestCase): def test_add_user(self): self.assertEqual(User.all().count(), 0) Setup.addFirstTimeUser() self.assertEqual(User.all().count(), 1) ## Rerun Setup.addFirstTimeUser() self.assertEqual(User.all().count(), 1) def test_get_all_users(self): self.assertTrue(User.all() > 0) if __name__ == '__main__': unittest.main(testRunner=TeamcityTestRunner())
import sys import unittest try: from teamcity import is_running_under_teamcity from teamcity.unittestpy import TeamcityTestRunner runner = TeamcityTestRunner() if is_running_under_teamcity() else unittest.TextTestRunner() except ImportError: runner = unittest.TextTestRunner() from tests import ExampleTest tests = { "ExampleTest": ExampleTest } if __name__ == "__main__": from application import application application.start_testing() test_name = sys.argv[1] if len(sys.argv) > 1 else None tests = tuple( [ unittest.loader.findTestCases(tests[test_suit_name]) for test_suit_name in tests if test_suit_name == test_name or not test_name ] ) sys.exit(not runner.run(unittest.TestSuite(tests=tests)).wasSuccessful())