def run(self, context): if any(self.test_session_setup_task.teardown_funcs): # before actual teardown context.event_manager.fire(events.TestSessionTeardownStartEvent()) set_runtime_location(TreeLocation.in_test_session_teardown()) set_step("Teardown test session") # actual teardown context.run_teardown_funcs(self.test_session_setup_task.teardown_funcs) # after actual teardown context.event_manager.fire(events.TestSessionTeardownEndEvent())
def run(self, context): if any(self.suite_setup_task.teardown_funcs): # before actual teardown context.event_manager.fire(events.SuiteTeardownStartEvent(self.suite)) set_runtime_location(TreeLocation.in_suite_teardown(self.suite)) set_step("Teardown suite") # actual teardown context.run_teardown_funcs(self.suite_setup_task.teardown_funcs) # after actual teardown context.event_manager.fire(events.SuiteTeardownEndEvent(self.suite))
def run(self, context): setup_teardown_funcs = self.scheduled_fixtures.get_setup_teardown_pairs() if any(setup for setup, _ in setup_teardown_funcs): # before actual setup context.event_manager.fire(events.TestSessionSetupStartEvent()) set_runtime_location(TreeLocation.in_test_session_setup()) set_step("Setup test session") # actual setup self.teardown_funcs = context.run_setup_funcs(setup_teardown_funcs, TreeLocation.in_test_session_setup()) # after actual setup context.event_manager.fire(events.TestSessionSetupEndEvent()) if not is_location_successful(TreeLocation.in_test_session_setup()): raise TaskFailure("test session setup failed") else: self.teardown_funcs = [teardown for _, teardown in setup_teardown_funcs if teardown]
def run(self, context): if any(setup for setup, _ in self.setup_teardown_funcs): # before actual initialization context.event_manager.fire(events.SuiteSetupStartEvent(self.suite)) set_runtime_location(TreeLocation.in_suite_setup(self.suite)) set_step("Setup suite") # actual initialization self.teardown_funcs = context.run_setup_funcs( self.setup_teardown_funcs, TreeLocation.in_suite_setup(self.suite) ) # after actual initialization context.event_manager.fire(events.SuiteSetupEndEvent(self.suite)) if not is_location_successful(TreeLocation.in_suite_setup(self.suite)): raise TaskFailure("suite '%s' setup failed" % self.suite.path) else: self.teardown_funcs = [teardown for _, teardown in self.setup_teardown_funcs if teardown]
def run(self, context): suite = self.test.parent_suite ### # Checker whether the test must be executed or not ### if self.test.is_disabled() and not context.force_disabled: context.event_manager.fire(events.TestDisabledEvent(self.test, "")) return ### # Begin test ### context.event_manager.fire(events.TestStartEvent(self.test)) set_runtime_location(TreeLocation.in_test(self.test)) ### # Setup test (setup and fixtures) ### setup_teardown_funcs = list() if suite.has_hook("setup_test"): def setup_test_wrapper(): suite.get_hook("setup_test")(self.test) else: setup_test_wrapper = None if suite.has_hook("teardown_test"): def teardown_test_wrapper(): status_so_far = "passed" if is_location_successful(TreeLocation.in_test(self.test)) else "failed" suite.get_hook("teardown_test")(self.test, status_so_far) else: teardown_test_wrapper = None setup_teardown_funcs.append((setup_test_wrapper, teardown_test_wrapper)) scheduled_fixtures = context.fixture_registry.get_fixtures_scheduled_for_test( self.test, self.suite_scheduled_fixtures ) setup_teardown_funcs.extend(scheduled_fixtures.get_setup_teardown_pairs()) if any(setup for setup, _ in setup_teardown_funcs): context.event_manager.fire(events.TestSetupStartEvent(self.test)) set_step("Setup test") teardown_funcs = context.run_setup_funcs(setup_teardown_funcs, TreeLocation.in_test(self.test)) context.event_manager.fire(events.TestSetupEndEvent(self.test)) else: teardown_funcs = [teardown for _, teardown in setup_teardown_funcs if teardown] ### # Run test: ### if is_location_successful(TreeLocation.in_test(self.test)): test_func_params = scheduled_fixtures.get_fixture_results(self.test.get_fixtures()) set_step(self.test.description) try: self.test.callback(**test_func_params) except Exception as e: context.handle_exception(e, suite) ### # Teardown ### if any(teardown_funcs): context.event_manager.fire(events.TestTeardownStartEvent(self.test)) set_step("Teardown test") context.run_teardown_funcs(teardown_funcs) context.event_manager.fire(events.TestTeardownEndEvent(self.test)) context.event_manager.fire(events.TestEndEvent(self.test)) if not is_location_successful(TreeLocation.in_test(self.test)): raise TaskFailure("test '%s' failed" % self.test.path)