Execute Unit Tests with Python 3
I use catkin as build system for a package using Python 3. So far this has not been a problem as our code does not really use ROS at all (except from catkin).
Now I added Python unit tests using the following structure:
#!/usr/bin/env python3
import unittest
class TestFoobar(unittest.TestCase):
def test_foo(self):
...
if __name__ == "__main__":
import rosunit
rosunit.unitrun("my_package", 'test_foobar', TestFoobar)
When I execute the test directly (e.g. via rosrun my_package test_foobar.py
), the test is running with Python 3 and all is good. However, when running catkin run_tests
, the shebang seems to be ignored and the test is executed with Python 2 (which fails due to incompatibilities).
Unfortunately, I'm still stuck with ROS Kinetic on Ubuntu 16.04.
So the actual question: Is there a way with Kinetic to make the tests being executed with Python 3?
I already tried adding -DPYTHON_EXECUTABLE=/usr/bin/python3
which works for building but does not seem to have an effect on the test.
Does wiki/UsingPython3 discuss this at all?
If not: would be good to add.
UsingPython3/SourceCodeChanges mentions "In general, tests and CMake logic should invoke scripts with python2 or python3 rather than relying on the shebang." at the bottom but without mentioning on how I can change which version it uses. I also found out about
ROS_PYTHON_VERSION
there and tried setting it to 3 without success (not sure if this variable is even considered at all by Kinetic?).Hi Felix, Did you find a solution for this? I'm getting the same problem. Thanks.
Unfortunately not. I'm simply running the tests manually for now. I'll anyway move to ROS2 soon, which hopefully should fix this problem.