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:

[platformio]
src_dir = ./

[env]
extra_scripts =
pre:prebuild-include.py

[env:f446rc]
platform = ststm32
board = genericSTM32F446RC
framework = stm32cube

[env:f401re]
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?

Thanks