Hey @danielhep! Great question.
What I’ve used in the past is to create a header_overrides directory where I have my mocks, stubs, and fakes directory. For reference, this section mentions it (briefly) Embedded C/C++ Unit Testing Basics | Interrupt.
Place any header in that folder, with the structure you are trying to match, and then include that directory before any of the include paths you are trying to override. This will ensure that CppUTest picks up your overridden header first before the MCU one.
For example, if you are trying to override a fake header that is included in the form of
#include stm32/inc/stm32f4xx.h
then make this the structure within header_overrides
$ tree header_overrides
header_overrides
└── stm32
└── inc
└── stm32f4xx.h
EDIT: I missed your last sentence:
I need to keep the driver headers included since I use some of the typedefs in them.
My solution has always been to redefine the typedefs in the override header. If things change, the unit tests will just break but that’s usually fine. The worst would be if the overridden header changed and things didn’t break.