Can I set different build flags for normal build vs (unit) test build

I’m testing a networking library. During these tests I want to disable OTA firmware upgrades, but for a normal build they should be on.

I was thinking about adding a build flag ‘allowFirmwareUpgrades’ to control this, but then this flag should have different value for normal build vs test build…

I could fix this with having separate environments, but that’s kind of a dirty workaround.

That’s exactly what environments are for IMHO. I wouldn’t call it a “dirty workaround”.

Settings different build flags for unit tests would double the number of environments. I think it makes more sense to be able to set different flags in the same environment, similar to how you can set debug build flags different from release build flags.

Well, if you’re worried about settings duplication, I’ve solved it like this:

I have my unit testing env changes not commited/pushed yet [and it would better show reusing], but the idea is there.

I have found an even better option: Platformio.ini common settings for release and debug but not for native - #4 by dvdnwk

2 Likes