We have unit tests that require rospy (One of the test uses geometry_msgs/Twist).
When we run the unit tests locally, everything is fine.
pytest
============================= test session starts ==============================
platform linux -- Python 3.6.9, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: /home/cedric/Programming/robotics-prototype, inifile: pytest.ini
collected 10 items
tests/unit/branch_name_test.py ...... [ 60%]
tests/unit/drive_controls_test.py .. [ 80%]
tests/unit/import_test.py .. [100%]
========================== 10 passed in 2.73 seconds ===========================
When we run it on Travis, it fails. This is because it fails to find rospy. Our Travis setup installs ROS, runs catkin_make successfully, but fails at the unit tests.
The repo is public so if you're interesting in seeing the complete travis logs click here.
os: linux
dist: bionic
language: python
cache:
- apt
env:
global:
- REPO_ROOT=$(pwd)
- ARDUINO_IDE_VERSION="1.8.12"
- ARDUINO_PATH="$HOME/arduino-$ARDUINO_IDE_VERSION" # Required for CMake script
- TEENSYDUINO_VERSION="152"
- ROS_PYTHON_VERSION="3.6"
- ROS_VERSION="melodic"
- OS_VERSION="bionic"
install:
# Taken from this tutorial https://github.com/newdigate/teensy-blink
- mkdir -p robot/rover/build
- mkdir -p ~/Arduino/libraries
- wget --quiet https://downloads.arduino.cc/arduino-$ARDUINO_IDE_VERSION-linux64.tar.xz
- tar xf arduino-$ARDUINO_IDE_VERSION-linux64.tar.xz -C /home/$USER/
- curl -fsSL https://www.pjrc.com/teensy/td_$TEENSYDUINO_VERSION/TeensyduinoInstall.linux64 -o TeensyduinoInstall.linux64
- chmod +x TeensyduinoInstall.linux64
- /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16
- sleep 3
- export DISPLAY=:1.0
- ./TeensyduinoInstall.linux64 --dir=$ARDUINO_PATH
# Install pip dependencies and setup robot python package
- pip install -r requirements.txt -r requirements-dev.txt
- pip install -e .
# Install ros-base and necessary packages
- sudo sh -c "echo \"deb http://packages.ros.org/ros/ubuntu $OS_VERSION main\" > /etc/apt/sources.list.d/ros-latest.list"
- sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
- sudo apt update -q
- sudo apt install -y ros-$ROS_VERSION-ros-base ros-$ROS_VERSION-cv-camera ros-$ROS_VERSION-web-video-server
- sudo apt install -y python-rosdep python-wstool
# Install ros package dependencies
- cd $REPO_ROOT/robot/rospackages
- sudo rosdep init
- rosdep update
- rosdep install -y -r --from-paths src --ignore-src --rosdistro $ROS_VERSION
script:
# Set up 'robot' python module and test python installation
- cd $REPO_ROOT
- python setup.py develop
- pytest --continue-on-collection-errors
# Set up and initialize catkin workspace for ros packages
- cd $REPO_ROOT/robot/rospackages
- source /opt/ros/$ROS_VERSION/setup.bash
- catkin_make
# Allow to compile arduino code in external IDEs or something
- cd $REPO_ROOT/robot/rover/build
- cmake ..
- make
notifications:
email:
recipients:
- (hidden for the purpose of the question)
on_success: change
on_failure: change
python:
- "3.6"
git:
submodules: true
It seems that you are calling the test before sourcing your ROS environment. You need change that around:
script:
# Set up and initialize catkin workspace for ros packages
- cd $REPO_ROOT/robot/rospackages
- source /opt/ros/$ROS_VERSION/setup.bash
- catkin_make
# Set up 'robot' python module and test python installation
- cd $REPO_ROOT
- python setup.py develop
- pytest --continue-on-collection-errors