def _run_setup_and_topic(ctx_obj, index): # If we're already mid-skip, don't run anything if skipReason: raise skipReason # Run setup function try: ctx_obj.setup() except Exception: raise VowsTopicError('setup', sys.exc_info()) # Find & run topic function if not hasattr(ctx_obj, 'topic'): # ctx_obj has no topic return ctx_obj._get_first_available_topic(index) try: topic_func = ctx_obj.topic topic_list = get_topics_for(topic_func, ctx_obj) start_time = time.time() if topic_func is None: return None topic = topic_func(*topic_list) ctx_result['topic_elapsed'] = elapsed(start_time) return topic except SkipTest: raise except Exception: raise VowsTopicError('topic', sys.exc_info())
def _run_teardown(): try: for blocker in teardown_blockers: blocker.join() ctx_obj.teardown() except Exception: raise VowsTopicError('teardown', sys.exc_info())
def _run_with_topic(topic): def _run_vows_and_subcontexts(topic, index=-1, enumerated=False): # methods for vow_name, vow in vows: if skipReason: skipped_result = self.get_vow_result( vow, topic, ctx_obj, vow_name, enumerated) skipped_result['skip'] = skipReason ctx_result['tests'].append(skipped_result) else: vow_greenlet = self._run_vow(ctx_result['tests'], topic, ctx_obj, vow, vow_name, enumerated=enumerated) teardown_blockers.append(vow_greenlet) # classes for subctx_name, subctx in subcontexts: # resolve user-defined Context classes if not issubclass(subctx, self.context_class): subctx = type(ctx_name, (subctx, self.context_class), {}) subctx_obj = subctx(ctx_obj) subctx_obj.pool = self.pool subctx_greenlet = self.pool.spawn( self.run_context, ctx_result['contexts'], subctx_name, subctx_obj, execution_plan['contexts'][subctx_name], index=index, suite=suite or ctx_result['filename'], skipReason=skipReason) teardown_blockers.append(subctx_greenlet) # setup generated topics if needed is_generator = inspect.isgenerator(topic) if is_generator: try: ctx_obj.generated_topic = True topic = ctx_obj.topic_value = list(topic) except Exception: # Actually getting the values from the generator may raise exception raise VowsTopicError('topic', sys.exc_info()) else: ctx_obj.topic_value = topic if is_generator: for index, topic_value in enumerate(topic): _run_vows_and_subcontexts(topic_value, index=index, enumerated=True) else: _run_vows_and_subcontexts(topic)
def topic(self): # Simulate a context whose topic() function raised an error mock_exc_info = ('type', 'value', 'traceback') context = { 'contexts': [], 'error': VowsTopicError('topic', mock_exc_info), 'filename': '/path/to/vows.py', 'name': 'TestContext', 'tests': [], 'topic_elapsed': 0 } return context
def _run_setup_and_topic(ctx_obj, index): # Run setup function try: ctx_obj.setup() except Exception as e: raise VowsTopicError('setup', sys.exc_info()) # Find & run topic function if not hasattr(ctx_obj, 'topic'): # ctx_obj has no topic return ctx_obj._get_first_available_topic(index) try: topic_func = ctx_obj.topic topic_list = get_topics_for(topic_func, ctx_obj) start_time = time.time() topic = topic_func(*topic_list) ctx_result['topic_elapsed'] = elapsed(start_time) return topic except Exception as e: raise VowsTopicError('topic', sys.exc_info())
def _run_with_topic(topic): def _run_vows_and_subcontexts(topic, index=-1, enumerated=False): # methods for vow_name, vow in vows: self._run_vow( ctx_result['tests'], topic, ctx_obj, teardown.wrap(vow), vow_name, enumerated=enumerated) # classes for subctx_name, subctx in subcontexts: # resolve user-defined Context classes if not issubclass(subctx, self.context_class): subctx = type(ctx_name, (subctx, self.context_class), {}) subctx_obj = subctx(ctx_obj) subctx_obj.pool = self.pool subctx_obj.teardown = teardown.wrap(subctx_obj.teardown) self.pool.spawn( self.run_context, ctx_result['contexts'], ctx_name=subctx_name, ctx_obj=subctx_obj, index=index, suite=suite or ctx_result['filename'] ) # setup generated topics if needed is_generator = inspect.isgenerator(topic) if is_generator: try: ctx_obj.generated_topic = True topic = ctx_obj.topic_value = list(topic) except Exception as e: # Actually getting the values from the generator may raise exception raise VowsTopicError('topic', sys.exc_info()) else: ctx_obj.topic_value = topic if is_generator: for index, topic_value in enumerate(topic): _run_vows_and_subcontexts(topic_value, index=index, enumerated=True) else: _run_vows_and_subcontexts(topic)
def topic(self): try: raise Exception('asdf') except: test_exc_info = sys.exc_info() result = ResultMock() result.successful_tests = 1 result.errored_tests = 0 result.skipped_tests = 0 result.total_test_count = 1 result.elapsed_time = 0 result.contexts = [{ 'name': 'Context1', 'tests': [], 'error': VowsTopicError('topic', test_exc_info), 'contexts': [], 'stdout': '', 'stderr': '' }] reporter = XUnitReporter(result) return reporter.create_report_document().firstChild.firstChild
def _run_teardown(topic): try: teardown() except Exception as e: raise VowsTopicError('teardown', sys.exc_info())