How about this:

```bash
# Populate a '|'-separated list of packages in the source path
export PKGS=$(for f in `ls $CI_SOURCE_PATH` ; do [ -d $f ] && echo -n "$f|" ; done)

# Filter these packages from the list of available targets (ie. look for run_tests_<package_name>)
# NOTE 1: Maybe you can optimize this command better, I overspent time getting to this
# point, awk is not my thing
# NOTE 2: I'm using 'make -C build' instead of 'catkin_make' because the latter also produces
# an extra 'Invoking "make" failed' in TESTS
export TESTS=`make -C build -qp | awk -F':' "/^(run_tests_)($PKGS):([^=]|$)/" | awk '{split($1,A,/:/);for(i in A)print A[i]}' | grep -v "^$"`
```