def run(self, test): session_start = time.monotonic() cases = tb.get_test_cases([test]) setup = tb.get_test_cases_setup(cases) servers = [] conns = [] bootstrap_time_taken = 0 tests_time_taken = 0 result = None try: if setup: self._echo('Populating test databases... ', fg='white', nl=False) max_conns = max(100, self.num_workers * len(setup) * 2) cluster = tb._init_cluster( init_settings={ # Make sure the server accomodates the possible # number of connections from all test classes. 'max_connections': max_conns, }, cleanup_atexit=False) servers, conns = tb.start_worker_servers( cluster, self.num_workers) tb.setup_test_cases(cases, conns) os.environ.update({'EDGEDB_TEST_CASES_SET_UP': "1"}) bootstrap_time_taken = time.monotonic() - session_start self._echo('OK.') start = time.monotonic() all_tests = list( itertools.chain.from_iterable(tests for tests in cases.values())) if self.num_workers > 1: suite = ParallelTestSuite(self._sort_tests(cases), conns, self.num_workers) else: suite = SequentialTestSuite(self._sort_tests(cases), conns) result = ParallelTextTestResult(stream=self.stream, verbosity=self.verbosity, warnings=self.warnings, failfast=self.failfast, output_format=self.output_format, tests=all_tests, suite=suite) unittest.signals.registerResult(result) self._echo() suite.run(result) tests_time_taken = time.monotonic() - start except KeyboardInterrupt: raise finally: if self.verbosity == 1: self._echo() if setup: self._echo() self._echo('Shutting down test cluster... ', nl=False) tb.shutdown_worker_servers(servers) self._echo('OK.') if result is not None: self._render_result(result, bootstrap_time_taken, tests_time_taken) return result
def run(self, test): self.cases.update(tb.get_test_cases([test])) return TestResult()