# Unittest \_\_init\_\_ exception handling

**URL:** <https://discuss.ray.io/t/unittest-init-exception-handling/13182>\
**Category:** Ray Core\
**Created:** [December 16, 2023, 9:41pm UTC](https://discuss.ray.io/t/unittest-init-exception-handling/13182 "2023-12-16T21:41:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yus](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/yus/32/5499_2.png) [@yus](https://discuss.ray.io/u/yus)\
**Post date:** [December 16, 2023, 9:41pm UTC](https://discuss.ray.io/t/unittest-init-exception-handling/13182/1 "2023-12-16T21:41:12Z")

</div>

How do you test for an exception that needs to occur in the ` __init__ ` of a ray actor class? I’m using unittest.

I tried

> with self.assertRaises(TypeError):  
> ray.get(actor\_ref)

But it gives a `ValueError: 'object_refs' must either be an ObjectRef or a list of ObjectRefs.`. Meanwhile, trying to trigger some random method with `ray.get(r.dummy_method.remote())` just hangs.

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [December 18, 2023, 10:16pm UTC](https://discuss.ray.io/t/unittest-init-exception-handling/13182/2 "2023-12-18T22:16:45Z")

</div>

I could do it using this script

```python3
import ray

ray.init()
@ray.remote
class A:
    def __init__ (self):
        raise ValueError

a = A.remote()
ray.get(a. __ray_ready__.remote())

```

---

<div class="post-metadata">

**Author:** ![yus](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/yus/32/5499_2.png) [@yus](https://discuss.ray.io/u/yus)\
**Post date:** [December 20, 2023, 7:26am UTC](https://discuss.ray.io/t/unittest-init-exception-handling/13182/3 "2023-12-20T07:26:07Z")

</div>

Thanks, but I’m specifically looking for catching this in a unit test. Is there a way to do that?
