I solved it. The problem was that my SamD21 board needs a delay after uploading for platormio unit tests to be monitored.
I am using a Prodino MKR GSM, but I assume this will apply to most SAMD21 boards.
The >2000ms delay mentioned in the docs is not enough. I am experiencing with my board I need a delay of 5000ms on setup(), and an extra script that delays for 5000ms after uploading.
This is mentioned in this post:
It would be great if the documentation could be updated to reflect this, as it is not obvious to find out what is happening.
Regards