Unit test with custom platform folder

I am using STM32Cube to generate codes for a specific chipset and put in into the platforms folder then use an extra script to select the right platform source code while building:

  • The folder structure is something like this:
    |- src
    |- lib
    | …
    |- platforms
    | - f401re
    | - f446rc
  • the platformio.ini is as below:

src_dir = ./

extra_scripts =

platform = ststm32
board = genericSTM32F446RC
framework = stm32cube

platform = ststm32
board = nucleo_f401re
framework = stm32cube

It worked well.

The problem is when running unit tests which also requires picking up the platform folder.

Is that the right approach for supporting multiple chipset platforms? how can I resolve the issue of unit testing?