PIO unit tests tries to access wrong serial port

Hey,
I have an issue with unit testing on an STM32G4 Nucleo board.
The one test I wrote compiles, links, and uploads fine, but after that, I’m getting:

[Errno 13] could not open port /dev/ttyS21: [Errno 13] Permission denied: '/dev/ttyS21'

This seems a bit strange to me, as the correct serial port of my board is ttyACM0. For that reason, I have specified

test_port = /dev/ttyACM0

in my platformio.ini. Still, PlatformIO tries to use ttyS21.
After googling and finding this, I used chmod to make ttyS21 accessible. I then get

Could not configure port: (5, 'Input/output error')

This might make sense, as it tries the wrong serial port anyway.
I tried adding a delay after uploading (in case the serial port briefly disappears and PIO therefore tries another one) using this, but neither did that help.

Any ideas?

Haven’t found a solution yet.
According to this Post, upload_port has no effect when upload_protocol = stlink. Now I am wondering if test_port has any effect.
That still wouldn’t explain why PIOs “default choice” is wrong, though.

“If test_port isn’t specified, the PlatformIO Unit Testing runner will try to detect it automatically.” - test_port — PlatformIO latest documentation