Best way for plugin checks

Hi,

in the past (and maybe also in the future) I made similar errors:

  1. forgot to add new class files to github, but import statement is there
  2. call unknown methods, because I renamed it
  3. ...other stupid thinks, like wrong type casting, missing not None checks, ....

Of course writing Python-Tests and execute before build is always a good idea, but if you forgot to write tests for the new class you have the same error.

I did a short test with mypy, but received some errors related to OctoPrint (beside my own)

mypy --py2 .

setup.py:52: error: Need type comment for 'plugin_additional_data' (hint: "plugin_additional_data = ...  # type: List[<type>]")
setup.py:72: error: Skipping analyzing 'setuptools': found module but no type hints or library stubs
setup.py:75: error: Cannot find implementation or library stub for module named 'octoprint_setuptools'
setup.py:102: error: Cannot find implementation or library stub for module named 'octoprint.util'
...
octoprint_PrintJobHistory/__init__.py:7: error: Cannot find implementation or library stub for module named 'octoprint.plugin'
octoprint_PrintJobHistory/__init__.py:7: error: Cannot find implementation or library stub for module named 'octoprint'
octoprint_PrintJobHistory/__init__.py:8: error: Cannot find implementation or library stub for module named 'octoprint.events'

How do you test your plugins in an automatic way?

There's several things you can do to test, some of which are not automatic and some are. I personally like automatic things, such as pre-commit and tests, but a wider testing audience can help massively.

Writing Python tests ensures that the modules can be imported properly, so if you forget to add referenced files before a release then it will automatically fail on the import error. I added some unit tests for a few plugins, for example here in Marlin EEPROM editor:

You could add a very simple test case that just imports all the known classes of your plugin to make sure they don't import things that don't exist.

The other thing I strongly recommend you do, is use a pre-release channel to get other people to test the plugin as well. It has worked very well for many of us and is configurable in the OctoPrint Software Update UI.

Here's a guide on how to add a 'Release Candidate' channel to your plugin:

That means you only roll out the plugin to a small number of people, recommend people who have reported bugs or requested features to test it - they usually do, since there is an incentive to do so.

Thank you very much for your feedback!

A simple testclass with just imports it is a clever idea, I will do that.
The "release channel" thing is already on my list.

There is a german phrase: "No time to sharpen the Axe, I need to chop wood."....but now it is the time for sharpen the axe :wink:

1 Like

That is a great quote @OllisGit and thanks for the quick merge on Spool Manager.