Ejemplo n.º 1
0
 def test_exception_record_deepcopy(self):
     """Makes sure ExceptionRecord wrapper handles deep copy properly."""
     try:
         raise RecordTestError('Oh ha!')
     except RecordTestError as e:
         er = records.ExceptionRecord(e)
     new_er = copy.deepcopy(er)
     self.assertIsNot(er, new_er)
     self.assertDictEqual(er.to_dict(), new_er.to_dict())
Ejemplo n.º 2
0
def expect_no_raises(message=None, extras=None):
    """Expects no exception is raised in a context.

    If the expectation is not met, the test is marked as fail after its
    execution finishes.

    A default message is added to the exception `details`.

    Args:
        message: string, custom message to add to exception's `details`.
        extras: An optional field for extra information to be included in test
            result.
    """
    try:
        yield
    except Exception as e:
        e_record = records.ExceptionRecord(e)
        if extras:
            e_record.extras = extras
        msg = message or 'Got an unexpected exception'
        details = '%s: %s' % (msg, e_record.details)
        logging.exception(details)
        e_record.details = details
        recorder.add_error(e_record)