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.

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\”, line 115, in main
cli() # pylint: disable=no-value-for-parameter
File “C:\Users\daede.platformio\penv\lib\site-packages\click\”, line 829, in call
return self.main(*args, **kwargs)
File “C:\Users\daede.platformio\penv\lib\site-packages\click\”, line 782, in main
rv = self.invoke(ctx)
File “C:\Users\daede.platformio\penv\lib\site-packages\platformio\”, line 44, in invoke
return super(PlatformioCLI, self).invoke(ctx)
File “C:\Users\daede.platformio\penv\lib\site-packages\click\”, line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “C:\Users\daede.platformio\penv\lib\site-packages\click\”, line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “C:\Users\daede.platformio\penv\lib\site-packages\click\”, line 610, in invoke
return callback(*args, **kwargs)
File “C:\Users\daede.platformio\penv\lib\site-packages\click\”, line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File “C:\Users\daede.platformio\penv\lib\site-packages\platformio\commands\test\”, line 171, in cli
“succeeded”: tp.process(),
File “C:\Users\daede.platformio\penv\lib\site-packages\platformio\commands\test\”, line 52, in process
File “C:\Users\daede.platformio\penv\lib\site-packages\platformio\commands\test\”, line 83, in run
line = ser.readline().strip()
File “C:\Users\daede.platformio\penv\lib\site-packages\serial\”, 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

  • Report this problem to the developers


Process finished with exit code 1


; 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
; +

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()

void setup()

void loop()

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