ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

[ROS2] colcon test discovery

asked 2021-03-29 03:09:08 -0500

lmiller gravatar image

Hi all,

I am writing some tests for my ROS2 Python package. I want to specify different levels of tests (unittest, integrationtests, system tests, ...) and run them with colcon test . I have the different tests in subfolders in the test directory:

├── launch
│   └──
├── my_pkg
│   ├──
│   ├──
│   ├──
│   ├──
│   └──
├── package.xml
├── resource
│   └── my_pkg
├── setup.cfg
└── test
    ├── integrationtest
    │   └──
    └── unittest

Colcon detects all tests, what is great. But sometimes I only want run e.g. the tests in the directory unittests. That woult be useful, because some of my integration or system tests needs a long time!

Are there any possibilities to run a specific subfolder of the test directory with colcon test? Have colcon some command line arguments for this? Or is there another way to go?

edit retag flag offensive close merge delete


Someone can correct me if I am wrong, but from my understanding of colcon test, there isn't a built-in way of selecting to only run tests from a given sub-folder of a package.

A workaround that comes to mind would be to create sub-packages (e.g. my_pkg_integrationtest, my_pkg_unittest) and to list them in my_pkg's package.xml as test_dependencies.

But I'd be surprised if there wasn't someone more knowledgeable out there with a better solution than that

shonigmann gravatar image shonigmann  ( 2021-03-29 21:45:16 -0500 )edit

Thanks for your reply. My first thought was also that I could call up the various tests via side-/sub-packages. However, I dont like the structure of my repository with too many sub-packages. As a current workaround I call pytest instead of colcon test like:

python3 -m pytest my_pkg/test/integrationtest

If someone has another way to call the tests only from a subfolder please let me know!

lmiller gravatar image lmiller  ( 2021-03-30 07:26:14 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2021-04-14 00:07:57 -0500

Dirk Thomas gravatar image

colcon simply invokes the unit testing framework used by each package when colcon test is being called.

If that testing framework has command line options to select/deselect specific tests you can easily provide them through colcon. E.g. for pytest you can use colcon test --pytest-args ... and use any of the sophisticated options like:

edit flag offensive delete link more

Question Tools



Asked: 2021-03-29 03:09:08 -0500

Seen: 1,022 times

Last updated: Apr 14 '21