コード例 #1
0
 def test_suite_erred_message(self):
     err = RuntimeError("something broke")
     EventBroker.publish(event=TestEvent.suite_erred,
                         suite_name="spam",
                         exception=err)
     level, msg = self.logged()
     expect(msg).to(equal(format_exception(err)))
コード例 #2
0
def call_if_alive(ref, **kwargs):
    log = logger_for_module(__name__)
    func = ref()
    if func:
        log.debug(f"Executing {func}")
        try:
            func(**kwargs)
            log.debug(f"{func} exited cleanly")
        except Exception as e:
            log.error(format_exception(e))
コード例 #3
0
 def test_contains_exception_stack_trace(self):
     exception = RuntimeError("failed intentionally")
     self.publish(TestEvent.suite_started)
     self.publish(TestEvent.suite_erred, exception=exception)
     self.publish(TestEvent.suite_ended)
     test = self.extract_dummy_test()
     failures = test.findall("./error")
     expect(failures).to(have_length(1))
     failure = failures[0]
     expect(failure.text).to(contain(format_exception(exception)))
コード例 #4
0
 def test_does_not_time_out_if_empty_string(self):
     self.context.set_env(RUN_ALL_TIMEOUT="")
     tc = self.context.create_time_controller(target=self.exercise_sut)
     tc.start()
     sleep(0.05)
     tc.advance(hours=72)
     sleep(0.05)
     if tc.exception_caught is not None:
         raise AssertionError(format_exception(tc.exception_caught))
     assert tc.is_alive(), "Exited prematurely"
     self.pretend_process_is_stopped()
     tc.join()
コード例 #5
0
def convert_tests(test_results):
    tests = []
    for result in test_results:
        if result.start_time and result.end_time:
            duration = (result.end_time - result.start_time).total_seconds()
        else:
            duration = None
        tc = TestCase(
            name=result.name,
            elapsed_sec=duration,
            status=convert_status(result.status),
            timestamp=extract_timestamp(result),
        )
        if result.exception:
            if TestStatus.failed == result.status:
                tc.add_failure_info(message=exception_str(result.exception),
                                    output=format_exception(result.exception))
            elif TestStatus.erred == result.status:
                tc.add_error_info(message=exception_str(result.exception),
                                  output=format_exception(result.exception))
            elif TestStatus.skipped == result.status:
                tc.add_skipped_info(message=exception_str(result.exception))
        tests.append(tc)
    return tests
コード例 #6
0
    def test_logs_exception_from_subscriber(self):
        event = 42
        e = RuntimeError("I tried to think but nothing happened")

        def bad_subscriber(**kwargs):
            raise e

        EventBroker.subscribe(event=event, func=bad_subscriber)

        try:
            EventBroker.publish(event=event)
        except Exception:
            # We don't care whether an exception was thrown.
            # Another test covers that path.
            pass
        errors = [
            rec.msg for rec in self.context.logging.stored_records
            if rec.levelname == "ERROR"
        ]
        expect(errors).to(contain(format_exception(e)))
コード例 #7
0
 def test_test_erred_message(self):
     err = RuntimeError("So. There.")
     EventBroker.publish(event=TestEvent.test_erred, exception=err)
     level, msg = self.logged()
     expect(msg).to(equal(format_exception(err)))
コード例 #8
0
 def on_suite_erred(self, suite_name, exception=None, **kwargs):
     self._dummy_test_case = TestCase(name=suite_name, status="error")
     if exception:
         self._dummy_test_case.add_error_info(
             message=exception_str(exception),
             output=format_exception(exception))
コード例 #9
0
 def on_test_erred(self, exception, **kwargs):
     self._log.error(format_exception(exception))
コード例 #10
0
 def on_suite_erred(self, exception=None, **kwargs):
     self._log.error(format_exception(exception))