Stack Exchange
bazel test failing for tensorflow new op on MAC OS X
For the script:
import tensorflow as tf;  

class ZeroOutTest(tf.test.TestCase):  
    def testZeroOut(self):  
        zero_out_module = tf.load_op_library('/Users/sahilsingla/tensorflow/bazel-bin/tensorflow/core/user_ops/zero_out.so')  
        with self.test_session():  
            result = zero_out_module.zero_out([5, 4, 3, 2, 1])  
            value = result.eval()  
        self.assertAllEqual(value, [5, 0, 0, 0, 0])

if name == "main":  
    tf.test.main()  

This is the same script given in tensorflow's documentation in "creating a new op", https://www.tensorflow.org/versions/r0.11/how_tos/adding_an_op/index.html
When I run: bazel test tensorflow/python/kernel_tests:zero_out_op_test
I get the error: tensorflow.python.framework.errors.NotFoundError: dlopen(zero_out.so, 6): image not found.
The funny thing is this does load when I do : 
python -c "import tensorflow as tf;  
zero_out_module = tf.load_op_library('/Users/sahilsingla/tensorflow/bazel-bin/tensorflow/core/user_ops/zero_out.so')"

but doesn't load with bazel test.
Can anyone please suggest what I am doing wrong? How can this error be removed?

The "proper" way of doing it is to use relative paths, and add a dependency in BUILD file to make sure zero_out.so is available. However it's weird that absolute path doesn't work....you can run with strace -Ttf -e trace=open bazel test to see what file it's trying to open

Solved now. I had to change build rules.

@YaroslavBulatov: It is not working with relative path though. I had to specify the absolute path to zero_out.so to get it to work. Any idea how to make it work?

For those facing the same problem, I will suggest try building using
bazel build -c opt //tensorflow/g3doc/how_tos/adding_an_op:zero_out_op_kernel_1.so
bazel test //tensorflow/g3doc/how_tos/adding_an_op:zero_out_1_test
instead of how it is given in the tensorflow documentation.
You will get a good idea how to make it work.
