def test_repr_with_exception(): obs = Observation("an observation") obs.set_exception(ValueError("something is wrong")) assert repr( obs ) == """Observation(name='an observation', value=Unrecorded, exception=ValueError('something is wrong',))"""
def _run_tested_func(self, func, args, kwargs, name, context, raise_on_exception): ctx = deepcopy(self.get_context()) ctx.update(context) obs = Observation(name, ctx) obs.set_start_time() try: obs.record(func(*args, **kwargs)) except Exception as ex: obs.set_exception(ex) if raise_on_exception: raise finally: obs.set_end_time() return obs
def test_repr_with_exception(): obs = Observation("an observation") obs.set_exception(ValueError("something is wrong")) assert repr(obs) == """Observation(name='an observation', exception=ValueError('something is wrong',))"""