Another update:
An even better way to stop PIO from pulling false dependencies from src/main during testing is to exclude all src files via build_src_filter. Then you can avoid polluting your code with #ifndef PIO_UNIT_TESTING directives.
Your platformio.ini would look something like this:
[env:desktop]
platform = native
build_src_filter = -<*>
I also tried build_type = test, but I don’t see it having any effect on the issues at hand here. I honestly have no clue what it does - possibly nothing. The documentation states that it enables using the environmental variable PIO_UNIT_TESTING, but I’ve already confirmed that statement as false. That variable works fine without build_type = test.