Errors basic testing on Leonardo (pio test)

I realise this is probably a stupid question but I am having problems running unit tests on platformio. Building and uploading to my Leonardo board works perfectly fine on their own, even serial monitor works fine. But, when I try to run unit tests via “pio test” I just get a list of errors:

"
avrdude done. Thank you.

Testing…
If you don’t see any output for the first 10 secs, please reset board (press reset button)

Error: Traceback (most recent call last):
File “C:\Users\daede.platformio\penv\lib\site-packages\platformio_main_.py”, line 115, in main
cli() # pylint: disable=no-value-for-parameter
File “C:\Users\daede.platformio\penv\lib\site-packages\click\core.py”, line 829, in call
return self.main(*args, **kwargs)
File “C:\Users\daede.platformio\penv\lib\site-packages\click\core.py”, line 782, in main
rv = self.invoke(ctx)
File “C:\Users\daede.platformio\penv\lib\site-packages\platformio\commands_init_.py”, line 44, in invoke
return super(PlatformioCLI, self).invoke(ctx)
File “C:\Users\daede.platformio\penv\lib\site-packages\click\core.py”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “C:\Users\daede.platformio\penv\lib\site-packages\click\core.py”, line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “C:\Users\daede.platformio\penv\lib\site-packages\click\core.py”, line 610, in invoke
return callback(*args, **kwargs)
File “C:\Users\daede.platformio\penv\lib\site-packages\click\decorators.py”, line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File “C:\Users\daede.platformio\penv\lib\site-packages\platformio\commands\test\command.py”, line 171, in cli
“succeeded”: tp.process(),
File “C:\Users\daede.platformio\penv\lib\site-packages\platformio\commands\test\embedded.py”, line 52, in process
return self.run()
File “C:\Users\daede.platformio\penv\lib\site-packages\platformio\commands\test\embedded.py”, line 83, in run
line = ser.readline().strip()
File “C:\Users\daede.platformio\penv\lib\site-packages\serial\serialwin32.py”, line 275, in read
raise SerialException(“ClearCommError failed ({!r})”.format(ctypes.WinError()))
serial.serialutil.SerialException: ClearCommError failed (PermissionError(13, ‘The device does not recognize the command
.’, None, 22))

============================================================

An unexpected error occurred. Further steps:

  • Verify that you have the latest version of PlatformIO using
    pip install -U platformio command

  • Try to find answer in FAQ Troubleshooting section
    +https://docs.platformio.org/page/faq.html

  • Report this problem to the developers
    +https://github.com/platformio/platformio-core/issues

============================================================

Process finished with exit code 1
"

platformio.ino:

"
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; +https://docs.platformio.org/page/projectconf.html

[env:leonardo]
platform = atmelavr
board = leonardo
framework = arduino
"

i have a single file “test_main.cpp” in the test folder in the root of the project, which just contains:
"
#include <Arduino.h>
#include <unity.h>

void test_basic()
{
TEST_ASSERT_TRUE(true);
}

void setup()
{
delay(2000);
UNITY_BEGIN();
RUN_TEST(test_basic);
UNITY_END();
}

void loop()
{
delay(1);
}
"

At the end of the stack trace in the error output, there is a line “(PermissionError(13, ‘The device does not recognize the command
.’, None, 22))”
which suggests to me that it cant access a file somewhere. Any clues? What am I doing wrong?

This is a known timing issue with unit-testing microcontrollers that create a USB serial interface themselves for testing. Does Teensy 4.1 Unit Testing Issue - #5 by maxgerhardt help?

I followed your post and made the changes suggested. Everything runs perfect now. Thanks so much :slight_smile:

1 Like