UndefinedEnvPlatformError: Please specify platform for 'esp' environment
I’m receiving this error every time I run or test with platformio on an environment that is not the one mentioned in the error. I have two environments in my platformio.ini file, native and esp. The actual builds and tests run perfectly for both environments, but this error always shows when I run/test the native environment. A google search of "UndefinedEnvPlatformError" "platformio" returns only 3 results, none of which resolve this issue for me.
Any tips appreciated, thanks!
platformio version 6.1.15 running in the esphome/esphome docker container.
Here’s my .ini file. The project is an esphome external component, and this .ini file is for running tests. This file, and all other test files are located in a directory <external-component-dir>/test/.
The command I’m running is pio test --without-uploading -c test/platformio.ini -e native
Unfortunately, the topic title is the entire error. I’ll paste the output below. I just noticed that this error only shows if I add the verbosity flag(s) -v to the pio test command. Without the flag(s), there are no errors printed to the output. Here are examples of both.
Running pio test with native environment, no verbosity flags:
Processing * in native environment
---------------------------------------------------------------------------------------------------------------
Building...
Testing...
test/main.cpp:116: test_schedule_receives_name [PASSED]
test/main.cpp:117: test_schedule_receives_id [PASSED]
test/main.cpp:118: test_schedule_receives_lambda [PASSED]
test/main.cpp:119: test_schedule_contains_schedules [PASSED]
test/main.cpp:120: test_schedule_calculates_cronnext [PASSED]
test/main.cpp:121: test_schedule_cronNextExpired [PASSED]
test/main.cpp:122: test_schedule_cronLoop [PASSED]
------------------------------------- native:* [PASSED] Took 2.43 seconds -------------------------------------
=================================================== SUMMARY ===================================================
Environment Test Status Duration
------------- ------ -------- ------------
native * PASSED 00:00:02.434
================================== 7 test cases: 7 succeeded in 00:00:02.434 ==================================
Running pio test with native environment, one verbosity flag -v:
// I removed the bulk of the testing output here
[D][dynamic_cron]: setCronNext() 'test-name' to [1739098921, 2025-02-09 03:02:01], while crontab: 1 2 3 * * *, bypass: 0
test/main.cpp:122:test_schedule_cronLoop:PASS
-----------------------
7 Tests 0 Failures 0 Ignored
OK
------------------------------------- native:* [PASSED] Took 1.17 seconds -------------------------------------
UndefinedEnvPlatformError: Please specify platform for 'esp' environment
Note that last line of the output. Also note that this error only appears when I run the native environment, not when I run the the esp environment.
Re my .ini file, I figured there would be other issues unrelated to this error. Some of the lines were copied verbatim from the esphome-generated platformio.ini file of a project that incorporates this external component (that’s where the platformio/espressif32@^6.1.0 came from). I’m happy to hear your thoughts and critique, thanks!