Define an environment only for testing

Hi,
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:

[env:d1_mini]
platform = espressif8266@2.5.0
board = d1_mini
framework = arduino
monitor_speed = 115200
test_filter = d1_mini

[env:native]
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

[platformio]
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.

https://docs.platformio.org/en/latest/integration/ide/vscode.html#task-explorer

2 Likes

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

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

My config:

[platformio]
default_envs = development

[env]
platform = espressif32
board = esp-wrover-kit
framework = arduino
lib_deps =
    SparkFun CCS811 Arduino Library@2.0.1
    SparkFun BME280@2.0.8
    ArduinoJson@6.15.2

[env:development]
build_flags = 
    -D WIFI_SSID=${sysenv.WIFI_SSID}
    -D WIFI_PASSWORD=${sysenv.WIFI_PASSWORD}
    -D API_URL=${sysenv.API_URL}
    -D API_AUTH_STRING="weatherstation:donotuseinproduction"

[env:production]
build_flags = 
    -D API_AUTH_STRING=${sysenv.API_AUTH_STRING}

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

image

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: Your Gateway to Embedded Software Development Excellence 👽.

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.