Trying to make a clean unit test for private library

Hi,
I have collected some experiences with PIO, so now I am trying to setup a “clean” boilerplate project to use for several similar projects.

My idea was to have a structure like this (in reality it has already a split for native and embedded testing, but for simplicity purposes I omit it)

lib
|-Preferences
  |-nvs_preferences.cpp (here're wrappers for ESP-IDF Preferences library)
  |-nvs_preferences.h 
src
|-main.cpp (with #include <nvs_preferences.h> and a call.
test
|-test_preferences.cpp (with a mock for Preferences class and an include of nvs_preferences.cpp

Build is successful, however when I try to run a test, it always tries to build the sources from the lib and gets of course:

Building & Uploading...
lib/Preferences/nvs_preferences.cpp: In function 'void readIOT()':
lib/Preferences/nvs_preferences.cpp:52:5: error: 'Preferences' was not declared in this scope

I can stop lib/Preferences from being built it if I add the library to lib_ignore = Preferences in platformio.ini, then I can test, but cannot build.

Everything works if all the sources are under src, then the libraries do not get built automatically for test, but it becomes messy at some point as the project grows and I want to get some code reuse across the projects, that’s why I started to create a clean structure in the first place.

I haven’t found an option to exclude libraries from being built only for testing. Can you please suggest a clean way out? To me the problem doesn’t sound like something very specific, I’d say everyone who use private libraries would stumble upon this once they try to unit test the code…

Thanks!