Define an environment only for testing

I’d like to know if it’s possible to ignore a specific platform when building or uploading a project.
I defined a native environment to run unit tests, but now each time I want to build/upload a project it tries to do it for the native platform as well.
Is there any way to solve prevent this?

My platform.ini file looks like this:

platform = espressif8266@2.5.0
board = d1_mini
framework = arduino
monitor_speed = 115200
test_filter = d1_mini

platform = native
test_filter = native

Thanks in advance!

PlatformIO by default tries to execute the target (run, upload, …) on every environment in the list.

That’s why we have a default_envs (docs) option to only select one or more default targets. So you write

default_envs = d1_mini

at the top of the platformio.ini, the “Run” / “Upload” button will only be executed in the d1_mini environment.

Or, use the environmnent-specific buttons in VSCode.


Cool, that’s what I was looking for! Thanks @maxgerhardt !

I don’t see these buttons, any ideas why?

My config:

default_envs = development

platform = espressif32
board = esp-wrover-kit
framework = arduino
lib_deps =
    SparkFun CCS811 Arduino Library@2.0.1
    SparkFun BME280@2.0.8

build_flags = 
    -D WIFI_SSID=${sysenv.WIFI_SSID}
    -D API_URL=${sysenv.API_URL}
    -D API_AUTH_STRING="weatherstation:donotuseinproduction"

build_flags = 

These buttons? They should be in the status bar at the bottom… Circled are three of them… PIO Home, Build and Upload…


Thanks, but no I was referring to the environment specific buttons linked in a previous post by maxgerhardt PlatformIO IDE for VSCode — PlatformIO latest documentation

I’ve understood that I can define different environments in the platformio.ini-file, but how do I choose which to execute? In “regular” VSCode you’d define something in .vscode/launch.json, but what is the equivalent in PlatformIO?

Click on “PlatformIO: Run tasks” button next the beaker icon in the bottom status bar.
From the list scroll down and click PlatformIO

There you will see all the tasks as per configured platform.ini

Alternatively, Click on PIO home icon on the left side bar → Project tasks will have all the tasks env-wise.

1 Like

I’ve copy-pasted your ini file in a sample project and I immedeately get the buttons described in the docs in the end of the project task list.

If that’s not the case for you file a bug report at GitHub - platformio/platformio-core: A professional collaborative platform for embedded development.

You use the ‘run tasks’ button option mentioned by @ajaybhargav or used the PIO icon on the left sidebar, expand the section/environment for the board you want to build/upload/debug/etc, and then use the build/upload/debug options listed under that environment.